Request to add an option not to auto-submit checkout form
-
Hello,
We have just upgraded to the latest plugin, now it uses the /build/ folder to load the js checkout files for applepay . We need a way for both google and apple pay to have the option not to auto-submit the checkout.
So when the users “comes back” from apple/google pay modal, the information is filled in the checkout, but not submitted yet.
-
Hi @shirgans
Thank you for contacting Payment Plugins. Did you observe the form wasn’t submitted in past versions of the plugin? That logic hasn’t changed in the more recent versions.
To stop the form from being submitted you can use the jQuery event that WooCommerce triggers. Here is an example:
let placeOrderClicked = false;
jQuery('form.checkout').on('checkout_place_order_stripe_applepay, checkout_place_order_stripe_payment_request', () => {
return placeOrderClicked;
});
jQuery(document.body).on('#place_order', 'click', () => {
placeOrderClicked = true;
});WooCommerce will stop the form submit if this jQuery event returns false. What this code does it listens for the place order button click event. If the place order button is clicked, the form is allowed to submit since that means the customer clicked the place order button.
Kind Regards
Thank you. But actually, there is also a validation that happens once the token recieved, and since we have custom validation it shows some wrong messages. we also need to trigger some of our code once the token recieved. How can we do that?
Hi @shirgans
we also need to trigger some of our code once the token recieved. How can we do that?
Can you please share your custom validation code?
Kind Regards
Google Pay
GPay.prototype.on_token_received = function () {
wc_stripe.CheckoutGateway.prototype.on_token_received.apply(this, arguments);
if (this.payment_request_options.shippingAddressRequired) {
this.maybe_set_ship_to_different();
}
this.fields.toFormFields({update_shipping_method: false});
jQuery('#shipping_email').val(jQuery('#billing_email').val());// Don't auto-submit, let user review the form first
console.log('GooglePay Token Received - user should review form before submitting');
$('body').trigger('googlepay_token_received');
// Original auto-submit disabled:
// if (this.checkout_fields_valid()) {
// this.get_form().trigger('submit');
// }
}
Apple PayApplePay.prototype.on_token_received = function () {
wc_stripe.CheckoutGateway.prototype.on_token_received.apply(this, arguments);
if (this.payment_request_options.requestShipping) {
this.maybe_set_ship_to_different();
}
this.fields.toFormFields({update_shipping_method: false});jQuery(‘#shipping_email’).val(jQuery(‘#billing_email’).val());
// Don’t auto-submit, let user review the form first
console.log(‘ApplePay Token Received – user should review form before submitting’);
$(‘body’).trigger(‘applepay_token_received’);
// Original auto-submit disabled:
// if (this.checkout_fields_valid()) {
// this.get_form().trigger(‘submit’);
// }
}Hi @shirgans
So you were overriding the plugin’s payment integrations defined in the
wc-stripe.jsfile? The previous code I shared should work just fine and you can add any validations to that code that you want. The benefit there is it’s also upgrade independent.Kind Regards
I’ve tried it, it is not overriding the script.
Please review for syntax errors. Two quotations were missing.
let placeOrderClicked = false;
jQuery('form.checkout').on('checkout_place_order_stripe_applepay', 'checkout_place_order_stripe_payment_request', () => {
return placeOrderClicked;
});
jQuery(document.body).on('#place_order', 'click', () => {
placeOrderClicked = true;
});Is there a way to disable to auto validation that I think the plugin do/fire?
Is there a way to disable to auto validation that I think the plugin do/fire?
The plugin does not perform auto-validation beyond the terms and conditions checkbox for wallet based payment methods. All other validations are performed by WooCommerce during the checkout flow.
If you implement the code example that was provided it should work for you.
Kind Regards
You must be logged in to reply to this topic.