gpt4 book ai didi

php - 在 Woocommerce 中获取购物车运输标签和费用

转载 作者:可可西里 更新时间:2023-11-01 00:18:32 24 4
gpt4 key购买 nike

我需要在购物车页面的另一侧显示运费。

我试过:

<?php
$current_shipping_cost = WC()->cart->get_cart_shipping_total();
echo $current_shipping_cost;
?>

但打印值(value) nad 不运输成本的标题,因为我使用标题:“ express 与 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;
}
}

关于php - 在 Woocommerce 中获取购物车运输标签和费用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48124332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com