1

我在 WooCommerce 中遇到问题,当货件从一定数量开始为 0.00 欧元时。问题是购物车页面没有出现 0.00 欧元或免费。

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

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 欧元,还有另一个选项。我在下面的文章中发现了它

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

问题是,在客户通过电子邮件收到的关于他的购买和发送部分的发票的通知中,他没有放任何东西。据我调查,我没有发现任何东西。

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

谢谢

4

1 回答 1

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 文件中。测试和工作。

在此处输入图像描述

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

于 2019-01-29T10:27:30.330 回答