skip to Main Content

Change ‘No Shipping Available’ Text

By default, when no shipping methods are available, WooCommerce prints the text ‘There are no shipping methods available. Please double check your address, or contact us if you need any help.’. Sometimes this message is too vague, and sometimes it’s just not how we want to word it. Sometimes we want we may want to change the text based on certain variables in the cart. Before this had to be done by altering the template file, which can be such a hassle if you haven’t done it before. Well there is a better way!

Change the Message

The code snippet below changes the default text to something a little more helpful.

add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_no_shipping_text' ); // Alters message on Cart page
add_filter( 'woocommerce_no_shipping_available_html', 'change_no_shipping_text' ); // Alters message on Checkout page
function change_no_shipping_text() {

	return "Please call us to receive a shipping quote and complete your order: (888) 555-5555";
}

Change the Message with Added Criteria

By retrieving the cart information from the customer’s session, you can add criteria to the shipping method based upon what they are purchasing.

Change the Message Based on Subtotal

add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_no_shipping_text', 10, 1 ); // Alters message on Cart page
add_filter( 'woocommerce_no_shipping_available_html', 'change_no_shipping_text', 10, 1 ); // Alters message on Checkout page
function change_no_shipping_text( $default ) {
	// Retrieve subtotal of cart
	$subtotal = WC()->cart->subtotal;

	if( $subtotal < 10 )
		return "You must purchase at least $10 of products to complete your order.";

	else
		return $default;
}

Change the Message if a Specific Shipping Class is in the Cart

add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_no_shipping_text', 10, 1 ); // Alters message on Cart page
add_filter( 'woocommerce_no_shipping_available_html', 'change_no_shipping_text', 10, 1 ); // Alters message on Checkout page
function change_no_shipping_text( $default ) {
	// shipping class IDs that need the method removed
    $search_shipping_class = 42;

	// Retrieve shipping classes in cart
	$cart_shipping_classes = array();
	foreach( WC()->cart->cart_contents as $key => $values )
		$cart_shipping_classes[] = $values[ 'data' ]->get_shipping_class_id();

	$cart_shipping_classes = array_unique( $cart_shipping_classes );

	if( in_array( $search_shipping_class, $cart_shipping_classes ) )
		return "One or more of your items requires a separate shipping quote. Please call us to complete your order: (888) 555-5555";

	else
		return $default;
}

Note: To restrict shipping for items assigned to shipping class ’42’, please refer to this article

  • Was this article helpful ?
  • yesno
3 out of 4 visitors found this article helpful
Views: 1439
Back To Top