efi*_*ida 1 php ajax wordpress woocommerce
嗨,我的结帐页面有一些问题,当我更改页面上的付款方式时,结帐订单会自动提交,我想手动使用按钮。我尝试使用以下代码来禁用 ajax 调用,但似乎这不是 ajax 问题。
function script_disabled()
{
wp_dequeue_script( 'wc-checkout' );
}
add_action('wp_enqueue_scripts', 'script_disabled');
Run Code Online (Sandbox Code Playgroud)
小智 5
你对问题的描述有些不对劲。使用单选按钮更改付款方式不应自动提交订单。在我的安装中,此操作仅显示或隐藏付款方式的相应窗格。显示的窗格实际上具有提交订单的按钮。下面的代码是防止提交 AJAX 调用的 jQuery 事件处理程序。但是,我认为这不是解决您问题的正确方法。您所描述的行为不是 WooCommerce 结账页面应该如何工作。至少,它在我的安装中不会那样做,这对于结帐页面来说几乎是标准的。
jQuery( 'form.checkout' ).on( 'checkout_place_order', function() {
var $payment_method = jQuery( 'form.checkout input[name="payment_method"]:checked' ).val();
if ( /* your condition, e.g. "$payment_method == 'paypal'" */ ) {
// prevent the submit AJAX call
alert( 'submit cancelled!' );
return false;
}
// allow the submit AJAX call
return true;
});
Run Code Online (Sandbox Code Playgroud)
我不会使用此解决方案,因为我认为还有其他问题。