Reply 334197 to: how to add shipping class in product page

Avatar: Rose Tyler
Rose Tyler
Support staff
September 15, 2022 at 14:19

Hello,

Your code needs to be improved
Use next code snippet instead of your one

function etheme_child_product_shipping_banner() {
global $product;

$shipping_class = $product->get_shipping_class();

switch ( $shipping_class ) {
    case 'free-shipping':
        echo 'Free shipping on this item';
    break;
    case 'flat-rate':
        echo 'Flat rate shpping $10';
    break;
}
}
add_action('woocommerce_before_single_product', 'etheme_child_product_shipping_banner', 20 );

Result: https://prnt.sc/rLBkW2B8iuG4

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.