本文介绍了在Woocommerce中获得购物车的运输标签和费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在购物车页面的另一侧显示运费。
I need to display the shipping cost in other side of cart page.
我尝试过:
<?php
$current_shipping_cost = WC()->cart->get_cart_shipping_total();
echo $current_shipping_cost;
?>
但是打印价值并没有运费的标题,因为我使用标题:快递使用UPS 24/48小时4.90欧元…
But print value nad don't title of shipping cost, because i use as title: "Express delivery with UPS 24/48 hours 4.90 euro"…
如何在woocommerce中获得订单运输成本?
How can I get order shipping cost in woocommerce?
推荐答案
在购物车页面(或结帐页面)中获取并显示所选的运输方式标签(以及其他相关数据,如果需要) >:
To get and display the chosen shipping method label (and other related data, if needed) in cart page (or in checkout page):
foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){
if( WC()->session->get('chosen_shipping_methods')[0] == $method_id ){
$rate_label = $rate->label; // The shipping method label name
$rate_cost_excl_tax = floatval($rate->cost); // The cost excluding tax
// The taxes cost
$rate_taxes = 0;
foreach ($rate->taxes as $rate_tax)
$rate_taxes += floatval($rate_tax);
// The cost including tax
$rate_cost_incl_tax = $rate_cost_excl_tax + $rate_taxes;
echo '<p class="shipping-total">
<strong class="label">'.$rate_label.': </strong>
<span class="totals">'. WC()->cart->get_cart_shipping_total() .'</span>
</p>';
break;
}
}
这篇关于在Woocommerce中获得购物车的运输标签和费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!