Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 12, 2020 10:01
Embed
What would you like to do?
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