Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active September 19, 2019 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/1dfe6843c65e0e66899904c1b998867e to your computer and use it in GitHub Desktop.
Save xadapter/1dfe6843c65e0e66899904c1b998867e to your computer and use it in GitHub Desktop.
Snippet to show the notice message on WooCommerce Cart and Checkout if any particular word found in Address line one and two. PluginHive Shipping Plugins supported - https://www.pluginhive.com/product/multiple-carrier-shipping-plugin-woocommerce/, https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/, https://www.p…
/**
* Snippet to show the notice message on Cart and Checkout if any particular word found in Address line one and two.
* Created at : 24 July 2018
* Updated at : 24 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link :
*/
add_filter( 'woocommerce_package_rates', 'ph_add_notice_if_po_box_addresses', 10, 2 );
if( ! function_exists('ph_add_notice_if_po_box_addresses') ) {
function ph_add_notice_if_po_box_addresses( $shipping_rates, $package) {
$words = array( 'PO BOX' ); // Provide the text
$message_to_display = "UPS doesn't deliver on PO Box addresses. Please use correct address to use UPS Services."; // Message to display
$address_line_one_and_two = strtolower($package['destination']['address'].' '.$package['destination']['address_2']);
foreach( $words as $word ) {
if( strstr( $address_line_one_and_two, strtolower($word) ) !== false ) {
wc_add_notice( print_r($message_to_display, true), 'error' );
}
}
return $shipping_rates;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment