This code display custom messages on the WooCommerce product page based on the product’s shipping class, providing information about delivery or special handling.
function ts_display_shipping_class_on_product_page() { $product = wc_get_product(); $shipping_class = $product->get_shipping_class(); switch ( $shipping_class ) { case 'light-items': echo 'This item can be delivered by tomorrow'; break; case 'heavy-items': echo 'This items requires special handling while shipping'; break; } } add_action( 'woocommerce_single_product_summary', 'ts_display_shipping_class_on_product_page', 10 );
Output
The output shows that when a product with the shipping class ‘heavy-items’ is viewed on the product page, the message “”This item requires special handling while shipping” will be displayed.
![How to Show Custom Message Based on Shipping Class on Single Product Page?](https://www.tychesoftwares.com/wp-content/uploads/2023/12/shipping-class-message-for-specific-shipping-class-1024x477.png)
Similarly, when a product with the shipping class ‘light-items’ is viewed on the product page, the message “This item can be delivered by tomorrow” will be displayed.
![How to Show Custom Message Based on Shipping Class on Single Product Page?](https://www.tychesoftwares.com/wp-content/uploads/2023/12/shipping-message-for-specific-shipping-class1-1024x571.png)
Similar to the above customization, you can also display custom messages for products with limited stock in WooCommerce that informs customers about product availability and encouraging timely decisions.