Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active December 20, 2023 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xadapter/4844a611b2cc3458a3c1856aa5113842 to your computer and use it in GitHub Desktop.
Save xadapter/4844a611b2cc3458a3c1856aa5113842 to your computer and use it in GitHub Desktop.
Snippet to customize the “There are no shipping methods available..” message found on the WooCommerce cart or checkout page based on cart total weight. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
// For Cart Page.
add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message_if_weght_exceeds', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message_if_weght_exceeds', 10, 1 );
function wf_customize_default_message_if_weght_exceeds( $default_msg ) {
$weight_limit = 50;
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
global $woocommerce;
$cart_weight = $woocommerce->cart->get_cart_contents_weight();
if ( $cart_weight > $weight_limit ) {
if( empty( $custom_msg ) ) {
return $default_msg;
}
return $custom_msg;
}
return $default_msg;
}
@Dusty4848
Copy link

Thanks, Still working in woocommerce 3.6.4, and WP 5.2.2

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