Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #891317

    Zebzerg
    Participant

    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?

    #891806

    Thai
    Moderator

    Hi 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 🙂

    #891905

    Zebzerg
    Participant

    Hi! 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.

    #892960

    Rad
    Moderator

    Hi there,

    Would you mind providing your site’s URL that has this code?

    Thanks!

    #894941

    Zebzerg
    Participant
    This reply has been marked as private.
    #895032

    Zebzerg
    Participant

    After 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?

    #896039

    Rad
    Moderator

    Hi 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.