efirvida
efirvida

Reputation: 4855

woocommerce prevent checkout submit on payment method change

Hi I have some problems with the checkout page, when I change the payment method on the page the checkout order is submited automatically, and I want to be manually, using a button. I try this the following code to disable the ajax call but seems that this is not an ajax issue.

function script_disabled()
{
    wp_dequeue_script( 'wc-checkout' );
}

add_action('wp_enqueue_scripts', 'script_disabled');

Upvotes: 2

Views: 5702

Answers (1)

user8158124
user8158124

Reputation:

There is something not quite right about your description of the problem. Changing the payment method using the radio buttons should not automatically submit the order. On my installation this action just shows or hides the appropriate pane for the payment method. The shown pane actually has the button to submit the order. The code below is the jQuery event handler to prevent the submit AJAX call. However, I don't think this is the right solution to your problem. The behavior you are describing is not how the WooCommerce checkout page should work. At least, it doesn't behave that way on my installation, which is pretty much standard with respect to the checkout page.

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;
});

I would not use this solution as I think something else is wrong.

Upvotes: 9

Related Questions