【问题标题】:Append 0.00 € to shipping label when cost is zero in Woocommerce order notifications当 Woocommerce 订单通知中的成本为零时,将 0.00 欧元附加到运输标签
【发布时间】:2019-06-21 16:05:26
【问题描述】:

我在 WooCommerce 中遇到问题,当货物从一定金额开始为 0.00 欧元时。问题是购物车页面没有显示为 0.00 欧元或免费。

这可以通过在 php 函数文件中输入此代码来解决。我在this post看到了。

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;
}

如果您希望显示 0.00 欧元,还有另一个选项。 I discovered it in the following article.

function my_custom_show_price_with_free_shipping( $label, $method ) {

    $label = $method->get_label();

    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
            $label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
        }
    } else {
        $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
        if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
            $label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }

    return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'my_custom_show_price_with_free_shipping', 10, 2 );

问题是,在客户通过电子邮件收到的有关其购买的通知和发送部分的发票中,他没有输入任何内容。尽我所能调查,我没有发现任何东西。

我已经搜索过,但没有找到任何东西。你能帮我解决这个问题吗?

谢谢

【问题讨论】:

    标签: php wordpress woocommerce orders shipping-method


    【解决方案1】:

    对于订单、电子邮件通知(可能还有 PDF),您将使用如下内容:

    add_filter( 'woocommerce_order_shipping_method', 'custom_order_shipping_method_labels', 10, 2 );
    function custom_order_shipping_method_labels( $labels, $order ) {
        $total = 0;
        foreach ( $order->get_items('shipping') as $item ) {
            $total += $item->get_total();
        }
        if( $total == 0 ){
            $labels .= ' ' . wc_price( 0 );
        }
        return $labels;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    请记住,在某些情况下,一个订单可以有多种运输方式...

    【讨论】:

    • 太棒了!非常感谢您的帮助。它完美地工作。再次感谢。
    猜你喜欢
    • 2021-02-28
    • 1970-01-01
    • 2021-06-15
    • 2018-05-26
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    相关资源
    最近更新 更多