In this video I explained like how we restrict the pin codes for deliver the orders to the customers. It means accept orders only from the mentioned pin codes which is added from our end. And other pin codes are not validated and orders are not placed, if customers are enter some other pin codes which is not exist on our database.
#wordpress #woocommerce #shipping #websitedevelopement #ecommerce #tamil #pincode
The Source Code is
//Check Pincode
add_action('woocommerce_after_checkout_validation', 'validate_pincode_on_checkout');
function validate_pincode_on_checkout($fields) {
// Define your allowed pin codes
$allowed_pincodes = array('628702', '628703', '628203');
// Get the pincode entered by the customer
$billing_pincode = isset($_POST['billing_postcode']) ? sanitize_text_field($_POST['billing_postcode']) : '';
//$shipping_pincode = isset($_POST['shipping_postcode']) ? sanitize_text_field($_POST['shipping_postcode']) : '';
// Validate the pincode
if (!in_array($billing_pincode, $allowed_pincodes)) {
wc_add_notice('Sorry, Currently we do not deliver to your billing pincode.', 'error');
}
// if (!in_array($shipping_pincode, $allowed_pincodes)) {
// wc_add_notice('Currently we do not deliver to your billing pincode.', 'error');
// }
}
17 июн 2024