dongzaotiao2863 2019-01-28 15:49
浏览 39

在Woocommerce订单通知中,当成本为零时,将0.00欧元附加到运输标签

I have a problem in WooCommerce when the shipment is 0.00 euros from a certain amount.The question is that the cart page does not appear 0.00 euros or free.

This is solved by entering this code in the php functions file. I saw it in 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;
}

There is also another option if you want 0.00 Euros to appear. 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 );

The question is that in the notifications that the client receives via e-mail of his purchase and invoices in the sending part he does not put anything. As much as I have investigated, I have not found anything.

I have searched but I have not found anything. Can you help me with this?

Thank you

  • 写回答

1条回答 默认 最新

  • duanli0162 2019-01-29 10:27
    关注

    For orders, email notifications (and maybe PDF), you will use something like:

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

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    enter image description here

    Remember that an order can have multiple shipping methods in some cases...

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能