Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created June 21, 2019 14:24
Show Gist options
  • Save plugin-republic/e5259a0822915b45f356a5f65bef9807 to your computer and use it in GitHub Desktop.
Save plugin-republic/e5259a0822915b45f356a5f65bef9807 to your computer and use it in GitHub Desktop.
Prevent customers from certain zipcodes from checking out
<?php
function pr_validate_zipcodes( $fields, $errors ) {
// Enter your zip codes in this array
$excluded_zips = array( '12345', '23456' );
if( in_array( $fields['shipping_postcode'], $excluded_zips ) ) {
$errors->add( 'validation', 'That zipcode is not allowed' );
}
}
add_action( 'woocommerce_after_checkout_validation', 'pr_validate_zipcodes', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment