Skip to content

Instantly share code, notes, and snippets.

@WooForce
Created August 19, 2016 10:52
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 WooForce/d8ebf3d87993aad98c267d00d4d1ccf4 to your computer and use it in GitHub Desktop.
Save WooForce/d8ebf3d87993aad98c267d00d4d1ccf4 to your computer and use it in GitHub Desktop.
WooCommerce - Customize Cart / Checkout Page No Shipping Methods Available message based on Zip Code.
// For Cart Page.
add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
function wf_customize_default_message( $default_msg ) {
$zip_array = array(
'30031',
);
if ( in_array( WC()->customer->get_shipping_postcode() , $zip_array) ) {
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
if( empty( $custom_msg ) ) {
return $default_msg;
}
return $custom_msg;
}
return $default_msg;
}
add_filter('woocommerce_package_rates', 'wf_remove_shipping_options_for_particular_zip_codes', 8, 2);
function wf_remove_shipping_options_for_particular_zip_codes($rates, $package)
{
global $woocommerce;
$zip_array = array(
'30031',
);
if ( in_array( $woocommerce->customer->get_shipping_postcode() , $zip_array) ) {
$rates = array();
}
return $rates;
}
@isuer
Copy link

isuer commented Aug 21, 2019

What to do if customer is not logged in or address is not configured on registered users profile, in that case shipping calculation doesn't work and shipping message area is shows empty space. How can we address that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment