Defined shipping ZIP Code validation during checkout in WooCommerce

Runtime check pincode

// Validate
function action_woocommerce_after_checkout_validation( $data, $error ) {
// The accepted delivery zones
$del_zones_array = array( 500001, 500004, 500008, 500028, 500030, 500032, 500033, 500034, 500036, 500048, 500049, 500057, 500086, 500089 );

// If the postal is not within the array, deny checkout
if( ! in_array( $data[‘shipping_postcode’], $del_zones_array ) ) {
$error->add( ‘validation’, ‘The ZIP you provided is not available for deliveries.’ );
}
}
add_action(‘woocommerce_after_checkout_validation’, ‘action_woocommerce_after_checkout_validation’, 10, 2 );

Similar Posts