Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Show Custom Message Based on Shipping Class on Single Product Page?

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?

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?

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x