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 的表格变得肮脏来更新运费之外,还有更好的方法来实现这一目标吗?
提前致谢!!
这是 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)