Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 268
Abd Ur Rehman Avatar asked Jul 29 '16 09:07

Abd Ur Rehman


People also ask

How do I display shipping class in WooCommerce?

Adding a shipping class in WooCommerceGo to WooCommerce > Settings and click on the Shipping tab at the top. Then click on the Shipping classes link underneath. Now, enter the same of your shipping class and a slug. If you leave the slug empty it will be automatically filled in for you.

How do I remove shipping charges in WooCommerce?

To delete a shipping zone: Go to: WooCommerce > Settings > Shipping > Shipping Zones. Hover over Zone Name, and the option to Edit and Delete appear. Select Delete, and the Shipping Zone is deleted.

How do I add free shipping to a specific amount in WooCommerce?

Go to your shipping zone: WooCommerce → Settings → Shipping and select your shipping zone. Click the Add shipping method button and select the shipping methods. It works now. You have configured WooCommerce Free Shipping over amount.


1 Answers

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;
}
like image 64
Marc Avatar answered Oct 31 '22 23:10

Marc