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

前端 未结 2 1711
生来不讨喜
生来不讨喜 2021-01-13 02:04

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 ra

相关标签:
2条回答
  • 2021-01-13 02:11

    Here is what I did.
    1.Open \wp-content\plugins\woocommerce\includes\wc-cart-functions.php
    2.Search for wc_cart_totals_shipping_method_label function
    3.Replace if ( $method->cost > 0 ) with if ( $method->cost >= 0 ) and it should show the shipping cost even if it is set to 0.

    0 讨论(0)
  • 2021-01-13 02:30

    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;
    }
    
    0 讨论(0)
提交回复
热议问题