[英]Get the Cart shipping label and cost in Woocommerce
我需要在購物車頁面的另一側顯示運費。
我試過:
<?php
$current_shipping_cost = WC()->cart->get_cart_shipping_total();
echo $current_shipping_cost;
?>
但是打印價值和運費的標題不一樣,因為我用作標題:“UPS 24/48 小時快遞 4.90 歐元”...
如何在woocommerce中獲得訂單運費?
要在購物車頁面(或結帳頁面)中獲取並顯示所選的運輸方式標簽(以及其他相關數據,如果需要) :
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.