-
-
Save AmelieBassart/631c6cf6c2556d447858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode'); | |
function deny_pobox_postcode( $posted ) { | |
global $woocommerce; | |
$address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1']; | |
$postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode']; | |
$replace = array(" ", ".", ","); | |
$address = strtolower( str_replace( $replace, '', $address ) ); | |
$postcode = strtolower( str_replace( $replace, '', $postcode ) ); | |
if ( strstr( $address, 'pobox' ) || strstr( $postcode, 'pobox' ) ) { | |
WC_add_notice( "Sorry, we don't ship to PO BOX addresses." ); | |
} | |
} |
Hi folks, in which file should this snipped be placed?
Ditto on the thank you @MrFent !
I just tested the code that was on WooCommerce and it still allowed the order to go through. Changing up the notice line now to test again.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet still allows the order to go through. It just prints the message on the "order was successful" page. In order to prevent the order from going through, you need to specify that this is an error message: