Created
May 5, 2021 13:35
-
-
Save clifgriffin/42f87dd5f8debdbfbc0265b8dec3ed47 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Prevent PO box shipping | |
*/ | |
add_action( 'woocommerce_after_checkout_validation', 'deny_pobox_postcode' ); | |
function deny_pobox_postcode( $posted ) { | |
$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( sprintf( __( 'We Are Unable To Ship To PO Boxes. Please Enter Another Address' ) ), 'error' ); | |
} | |
} | |
add_action( 'cfw_update_checkout_after_customer_save', 'deny_pobox_postcode_during_ajax_update' ); | |
function deny_pobox_postcode_during_ajax_update() { | |
$address = WC()->customer->get_shipping_address(); | |
$postcode = WC()->customer->get_shipping_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( sprintf( __( 'We Are Unable To Ship To PO Boxes. Please Enter Another Address' ) ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment