首页 文章

Woocommerce结帐:通过“update_checkout”ajax事件更新费用或更新总价

提问于
浏览
1

所以,我通过javascript触发 update_checkout . 然后,我有 woocommerce_review_order_before_shipping 钩子中的函数 . 该功能是添加/删除 free_shipping 送货方式(它基于货到付款可用性) .

付款方式有两个单选按钮:

  • 直接转移

  • 货到付款

该脚本已经有效 . 因此,当我选择COD(货到付款)时,将自动选择免运费方式 .

但是,问题是 the total price did not changed, this indicates that the cost is still available . 嗯,它发生了变化,但现在已经很晚了 . 我说很晚了,因为当我通过选择直接银行转账单选按钮更改付款方式时,总价格已经过了 .

问题是,

  • 为什么在更改付款方式时总价格不会实时更新?好的,它改变了但是在下一个改变事件中 .

  • 什么是WooCommerce API来更新总价或更新成本?我应该把它放在哪里?

:)非常感谢您的回答

2 回答

  • 0

    WC API中的这两个函数应该有所帮助 .

    calculate_totals()calculate_shipping() .

    global $woocommerce;
    
    $woocommerce->cart->calculate_totals();
    $woocommerce->cart->calculate_shipping();
    
  • 0

    你在WC_AJAX中尝试过this函数:

    public static function update_order_review(){
    }
    

    致电:

    WC_AJAX::checkout();
    

相关问题