【发布时间】:2019-08-29 03:12:56
【问题描述】:
我已尝试在特定用户的许多答案中实现在此站点上找到的代码,以根据所选支付网关的更改或其他一些字段更改刷新结帐。但是,当 JS 包含在我的函数文件中时,我的结帐卡住了,并且我有 ajax 加载动画圆圈。
我已经尝试过改编代码:
Trigger ajax update_checkout event on shipping methods change in Woocommerce
Update checkout ajax event when choosing a payment gateway in Woocommerce
On country change ajax update checkout for shipping in Woocommerce
Change Pay button on checkout based on Woocommerce chosen payment method
add_filter( "woocommerce_product_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
add_filter( "woocommerce_product_variation_get_tax_class", "woo_diff_rate_for_user", 1, 2 );
function woo_diff_rate_for_user( $tax_class, $product ) {
// Get the chosen payment gateway (dynamically)
$chosen_payment_method = WC()->session->get('chosen_payment_method');
if( $chosen_payment_method == 'wdc_woo_credits'){
$tax_class = "Zero rate";
}
<script type="text/javascript">
(function($){
$('form.checkout').on( 'change', 'input[name^="payment_method"]', function() {
var t = { updateTimer: !1, dirtyInput: !1,
reset_update_checkout_timer: function() {
clearTimeout(t.updateTimer)
}, trigger_update_checkout: function() {
t.reset_update_checkout_timer(), t.dirtyInput = !1,
$(document.body).trigger("update_checkout")
}
};
$(document.body).trigger('update_checkout')
});
})(jQuery);
</script>
return $tax_class;
}
如果我不包含 JS/jQuery,我的函数会在更改运输方式并且页面在更改时刷新时根据付款选项更改税级。但是我需要在支付网关更改时而不是在更改运费时刷新结帐。
【问题讨论】:
标签: php jquery wordpress woocommerce payment-method