显示运费 WooCommerce

我正在使用 WooCommerce 的购物车小部件 ->mini-cart.php 我正在通过它向它添加产品,AJAX并自己添加了一些元素。标准它在购物车中显示小计价格,但我想在它之后显示运费,然后显示总价(subtotal + shipping)

所以购物车看起来像这样:

- Products in cart - Subtotal - Shipping costs - Total price (shipping + subtotal)

我已经添加了总价code

<p><?php echo WC()->cart->get_cart_total(); ?></p>

但是这个回声与小计的价格相同,因为没有添加运费。有人可以帮我加上运费吗?一些钩子或代码。


三国纷争
浏览 168回答 1
1回答

阿波罗的战车

要在购物车页面(或结帐页面)中获取并显示所选的运输方式标签(以及其他相关数据,如果需要):foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){&nbsp; &nbsp; if( WC()->session->get('chosen_shipping_methods')[0] == $method_id ){&nbsp; &nbsp; &nbsp; &nbsp; $rate_label = $rate->label; // The shipping method label name&nbsp; &nbsp; &nbsp; &nbsp; $rate_cost_excl_tax = floatval($rate->cost); // The cost excluding tax&nbsp; &nbsp; &nbsp; &nbsp; // The taxes cost&nbsp; &nbsp; &nbsp; &nbsp; $rate_taxes = 0;&nbsp; &nbsp; &nbsp; &nbsp; foreach ($rate->taxes as $rate_tax)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rate_taxes += floatval($rate_tax);&nbsp; &nbsp; &nbsp; &nbsp; // The cost including tax&nbsp; &nbsp; &nbsp; &nbsp; $rate_cost_incl_tax = $rate_cost_excl_tax + $rate_taxes;&nbsp; &nbsp; &nbsp; &nbsp; echo '<p class="shipping-total">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong class="label">'.$rate_label.': </strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="totals">'. WC()->cart->get_cart_shipping_total() .'</span>&nbsp; &nbsp; &nbsp; &nbsp; </p>';&nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP