我有一个自定义API端点,可以使用自定义类触发处理运费.
这很好.
我通过运行正常的计算函数来添加我的速率:
WC()->cart->calculate_shipping();
Run Code Online (Sandbox Code Playgroud)
我看到加入的费率:
//... 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"
Run Code Online (Sandbox Code Playgroud)
我可以在API方法或页面本身返回预期的运费:
echo WC()->cart->get_cart_shipping_total();
<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>10.00</span>
Run Code Online (Sandbox Code Playgroud)
但是当我得到购物车和购物车的总数时,我的测试项目的总数却没有找到运费.物品价格为30美元,我们看到的运费是10美元:
<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>30.00</span>
Run Code Online (Sandbox Code Playgroud)
我错误地认为get_cart并且get_cart_total应该返回运费吗?
欢迎任何有关如何进一步调试或理论测试的帮助.