Do you want to display a custom message to your customers about the ‘free shipping’ option in your WooCommerce store? You can use a code snippet to display a custom message on the cart and checkout pages based on the customer’s shipping method. This will help you provide more information about the shipping process to your customers.
add_action('woocommerce_cart_totals_after_shipping', 'ts_shipping_method_custom_message'); add_action('woocommerce_review_order_after_shipping', 'ts_shipping_method_custom_message'); // Function to display custom message for free shipping function ts_shipping_method_custom_message() { // Define your targeted shipping method(s) $targeted_shipping_methods = array('free_shipping:59'); // Replace with the actual shipping method ID(s) // Get the chosen shipping methods $chosen_methods = WC()->session->get('chosen_shipping_methods'); if (!empty($chosen_methods)) { $chosen_method = reset($chosen_methods); // Check if the chosen shipping method is in the targeted list if (in_array($chosen_method, $targeted_shipping_methods)) { echo '<tr class="shipping"> <td colspan="2" style="text-align:center">' . sprintf( __("Great choice! You have selected free shipping for your order") ) . '</td> </tr>'; } } }
Output
When a customer selects a shipping method, such as free shipping, a personalized message appears below the shipping details on the cart page.
![](https://www.tychesoftwares.com/wp-content/uploads/2023/12/WooCommerce-Custom-Message-based-on-free-shipping-Cart.png)
Also, it shows the custom message for the free shipping option on the WooCommerce checkout page as shown below.
![](https://www.tychesoftwares.com/wp-content/uploads/2023/12/WooCommerce-Custom-Message-based-on-free-shipping-Checkout.png)
Additionally, you can also display a custom message based on shipping zones in WooCommerce. This feature will automatically notify customers located outside your usual shipping area.