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.
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.
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.