【问题标题】:woocommerce checkout update shipping value more than oncewoocommerce 结帐不止一次更新运费
【发布时间】:2017-11-06 17:19:53
【问题描述】:

Woocommerce 允许使用下面的代码来更新运费。

$('body').trigger('update_checkout', { update_shipping_method: true });

我正在使用自定义运输插件,并且能够通过 ajax 更新成本并最终更新我的总数。 问题是,update_checkout 只能在 billing_address_1、billing_city、shipping_city 和其他一些字段发生更改时起作用。所以我必须做如下的事情:

$("#billing_address_1").trigger("keypress").val(function(i,val){return val + ' -';});
$('body').trigger('update_checkout', { update_shipping_method: true }); 

有没有更好的方法来实现这一点,而不是让 woocommerce 的表单变脏以更新运费?

提前致谢!!

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    这是由 woocommerce 设计的。此脚本假定更改地址或国家/地区时需要更新。

      jQuery('body').trigger('update_checkout');
    
      /* what this does is update the order review table but what it doesn't do is update shipping costs;
         the calculate_shipping function of your shipping class will not be called again;
         so if you were like me and you made a shipping method plugin and you had to change costs based on payment method then
         this is the only way to ensure it does just that
      */
    

    如果你想让事情正常工作,添加这个(到插件文件或functions.php):

    function action_woocommerce_checkout_update_order_review($array, $int)
    {
        WC()->cart->calculate_shipping();
        return;
    }
    add_action('woocommerce_checkout_update_order_review', 'action_woocommerce_checkout_update_order_review', 10, 2);
    

    引用自:https://gist.github.com/neamtua/bfdc4521f5a1582f5ad169646f42fcdf

    要了解原因,请阅读此票: https://github.com/woocommerce/woocommerce/issues/12349

    【讨论】:

    • 不幸的是,这不起作用。我也想通了, jQuery('body').trigger('update_checkout');始终有效但不会在客户端更新。我使用 ajax 来获取运费,我得到了更新的数字,但是在结帐页面上它无法更新,并且在提交订单时,使用了客户端结帐页面上的值,而不是 WC 会话上的值。我正在使用 WC 会话变量来更新运费率数组。
    • 我有普通的 wordpress 安装和店面并触发 dom 事件,重新加载运费。通常在 wordpress 中,其他插件会破坏某些行为。您确定所有字段都正确填充吗?你能给我一个链接到这个问题的网站吗?
    • 现在无法公开网址:我的运输插件使用谷歌地图显示路线,必须单击“当天交货”、“1 周交货”等服务选项,它会返回新的运费值.此运费值由 ajax 提交给 WC->session 变量,然后触发 checkout_update WC 完成其余工作。我可以给你发邮件链接..
    • 当然,如果您还有问题,请给我发电子邮件 daniel[at]pikselownia.com
    猜你喜欢
    • 2021-09-24
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 2020-05-11
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多