Tagged: x
-
AuthorPosts
-
April 20, 2016 at 1:55 am #891317
Hi!
I’m trying to add a confirmation dialog when you place an order during checkout. This is the code i have so far but it doesn’t work as intended.
$("form[name='checkout']").submit(function (e) { if($("#payment_method_bacs").is(":checked")) { var choice = confirm("Are you sure that you want to complete the order using Direct Bank Transfer as payment method?"); if(choice == true) { alert("true"); return true; } else { alert ("false"); e.preventDefault(); return false; } }; });
The dialog pops up but when i click cancel the form is still submitted. Do you have any idea what I can do to avoid the form being submitted?
April 20, 2016 at 8:45 am #891806Hi There,
Please try with this code instead:
jQuery(function($){ $("form[name='checkout']").submit(function (e) { if($("#payment_method_bacs").is(":checked")) { var choice = confirm("Are you sure that you want to complete the order using Direct Bank Transfer as payment method?"); if(choice == true) { alert("true"); return true; } else { alert ("false"); return false; } }; }); });
Hope it helps 🙂
April 20, 2016 at 9:49 am #891905Hi! Thank you for the answer.
But that code don’t work correctly either. The confirmation dialog pop ups but when i click cancel it doesn’t cancel the form submit. Instead it goes through with the form validation so I think there is another script that doesn’t get cancelled. So i need to somehow stop everything from running.
April 20, 2016 at 11:08 pm #892960Hi there,
Would you mind providing your site’s URL that has this code?
Thanks!
April 22, 2016 at 2:56 am #894941This reply has been marked as private.April 22, 2016 at 4:17 am #895032After some more digging I think the problem is that the script in wp-content\plugins\woocommerce\assets\js\frontend\checkout.js is still running after you cancel the submit. So I guess I need to cancel the submit before checkout.js is being executed.
So perhaps I have written in the wrong forum?
April 22, 2016 at 6:41 pm #896039Hi there,
According to the coding, yes, you may need to edit to directly integrate the dialog.
http://akracingeurope.eu/wp-content/plugins/woocommerce/assets/js/frontend/checkout.js
Another way is cancelling the Ajax request, but that only applies if Ajax is available. It’s best if you consult this to a woocommerce developer as they are more familiar with woocommerce core.
Thanks for understanding.
-
AuthorPosts