Do you want to display an additional message to customers based on a specific shipping class on the WooCommerce Checkout page? Then the code below helps to achieve this.
add_action( 'woocommerce_review_order_before_order_total', 'ts_checkout_shipping_class_message' ); function ts_checkout_shipping_class_message(){ // Here your shipping class slugs in the array $shipping_classes = array('heavy-items'); // Here your shipping message $message = __("Please add some shipping details in order notes field.", "woocommerce"); // Loop through cart items foreach( WC()->cart->get_cart() as $cart_item ){ $shipping_class = $cart_item['data']->get_shipping_class(); // echo '<pre>' . print_r($shipping_class, true) . '</pre>'; // Uncomment for testing // Check cart items for specific shipping class, displaying a message if( in_array($shipping_class, $shipping_classes ) ){ echo '<tr class="shipping-note"> <td colspan="2"><strong>'.__("Note", "woocommerce").':</strong> '.$message.'</td> </tr>'; break; } } }
Output
Whenever a customer adds products belonging to a specific class (in this case, ‘heavy-items’), you can set a message as shown below to instruct them to do something.
You can also provide such custom messages early in the customer’s journey. Have a look into our post that guides well on how to show custom message based on shipping cass on single product page.