Created
December 19, 2018 11:36
-
-
Save varun-pluginhive/89ae4de38f5a4f5ef7a65f2a67fa1e34 to your computer and use it in GitHub Desktop.
Snippet to check for PO Box Address in Shipping Line Address 1 and 2 and throw the error if found. PluginHive Plugins : https://www.pluginhive.com/plugins/
This file contains 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
/** | |
* Snippet to check for PO Box Address in Shipping Line Address 1 and 2 and throw the error if found. | |
* Created at : 19 Dec 2018 | |
* Updated at : 19 Dec 2018 | |
* PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
* Gist Link : https://gist.github.com/varun-pluginhive/89ae4de38f5a4f5ef7a65f2a67fa1e34 | |
*/ | |
add_action( 'woocommerce_after_checkout_validation', function($data) { | |
$text_to_check = array( 'PO', 'PO.', 'PoBox' ); // Text to check in shipping address Line 1 and 2 | |
$message = "PO Box is not allowed please check your address."; | |
$text_to_check = array_map( "strtolower", $text_to_check ); // Change all the text to Lower | |
$po_in_addr_1 = array_intersect( $text_to_check, array_map( "strtolower", explode( ' ', $data['shipping_address_1'] ) ) ); | |
$po_in_addr_2 = array_intersect( $text_to_check, array_map( "strtolower", explode( ' ', $data['shipping_address_2'] ) ) ); | |
if( ! empty($po_in_addr_1) || ! empty($po_in_addr_2) ) | |
wc_add_notice( $message, "error" ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment