运费未显示在购物车总额中 - WooCommerce [英] Shipping cost not showing in cart total - WooCommerce

查看:30
本文介绍了运费未显示在购物车总额中 - WooCommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义 API 端点,它使用自定义类触发处理运输成本.

I have a custom API endpoint that triggers processing shipping costs using a custom class.

效果很好.

我通过运行正常的计算函数来添加我的费率:

I add my rate by running the normal calculate function:

WC()->cart->calculate_shipping();

我看到正在添加的费率:

I see the rate being added:

//... bunch of code to calculate cost
//... what it actually does here is irrelevant
$rate = array(
    'id' => $this->id,
    'label' => $this->title,
    'cost' => $cost
);

$this->add_rate( $rate );
echo "added rate at $cost";
//prints: "added rate at 10"

我可以在我的 API 方法或页面上返回预期的运费:

I can return the expected shipping cost in my API method or on the page itself:

echo WC()->cart->get_cart_shipping_total();

<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>10.00</span>

但是当我得到购物车和购物车总数时,我的测试项目有总数,但没有找到发货.商品成本为 30 美元,我们看到的运费为 10 美元:

But when I get the cart and cart total, there's the total for my test item but no shipping to be found. Item cost is $30, shipping as we've seen is $10:

<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>30.00</span>

我认为 get_cartget_cart_total 应该返回运费是错误的吗?

Am I wrong thinking that get_cart and get_cart_total should return the shipping cost?

欢迎任何有关如何进一步调试或理论测试的帮助.

Any help with how to further debug or theories to test are welcome.

推荐答案

终于弄明白了,其中一个太简单了,我不敢相信我没有早点弄明白.

Finally figured it out, one of those it's so easy I can't believe I didn't figure it out sooner type of things.

这只会获得购物车总数:

WC()->cart->get_cart_total();

这将获得订单的总金额:

WC()->cart->get_total();

这篇关于运费未显示在购物车总额中 - WooCommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆