Skip to content
Advertisement

How to show zero rate value of shipping class in cart page “WooCommerce”

I need some help in WooCommerce Shipping method. How can I show the value of shipping class on the cart page. Let me explain little bit my problem.

I added a flat rate to charge shipping for some products i.e. chairs €7 which is working perfect and show on cart page as => Shipping: Flat rate: €7 but I’ve some chairs to ship free to my customers. I added new class like “Free Shipping” and set the value to 0.00 EUR on checkout it’s no charging any cost which fine, but when client view cart and in shipping it only show the name of shipping method like Flat Rate without any cost because that was set to 0.00 which doesn’t convince the customer and he think we’ve hidden cost.

Is there any way to show the zero value of shipping class or is this possible to show the class name rather than shipping method’s title?

Advertisement

Answer

You can add a filter, checking if the cost of your shipping method is zero (WooCommerce currently is doing nothing else in their function than printing the “flat rate” label, if the cost isn’t above zero) and changing your label to whatever you’d like:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'add_free_shipping_label', 10, 2 );
function add_free_shipping_label( $label, $method ) {
    if ( $method->cost == 0 ) {
        $label = 'Free shipping'; //not quite elegant hard coded string
    }
    return $label;
}

Based on https://stackoverflow.com/a/23581656/8264519 and works like a charm.

Thank you @DhirenPatel for your question. The following additional code works for the thank you page and email:

add_filter( 'woocommerce_order_shipping_to_display', 'add_free_shipping_label_email', 10, 2 );
function add_free_shipping_label_email( $label, $method ) {
    if ( $method->cost == 0 ) {
        $label = 'Free shipping'; //not quite elegant hard coded string
    }
    return $label;
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement