【问题标题】:Shipping cost not showing in cart total - WooCommerce购物车中未显示运费总额 - WooCommerce
【发布时间】:2019-04-21 02:17:46
【问题描述】:

我有一个自定义 API 端点,它使用自定义类触发处理运费。

效果很好。

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

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

我看到正在添加的费率:

//... 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 方法或页面本身中返回预期的运费:

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 美元:

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

我认为get_cartget_cart_total 应该退回运费是不是错了?

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

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    终于想通了,其中一个很容易,我不敢相信我没有早点想通。

    这只会获得购物车总数

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

    这将获得订单的全部总额

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

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 1970-01-01
      • 2013-11-22
      • 2019-05-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多