Created
August 19, 2016 10:52
-
-
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.
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
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?