Support » Plugin: WooCommerce » Prevent user from reloading checkout page while payment is being processed

  • Resolved asafmoshejul

    (@asafmoshejul)


    After a user clicks the “Place Order” button on checkout page, the page is being blocked by an overlay and a loader GIF until the ajax finishes and the user is redirected to Thank You page.

    But, if a user reloads the checkout page while the payment is processing, a new order is being created and both of the orders are being charged.

    The basic thing is to use the ‘beforeunload’ event to warn the user before reloading.

    The problem is that ‘beforeunload’ catches also the automatic redirect to Thank You page, and pops alert after the payment was completed successfully and before redirecting to the Thank You page.

    I tried two methods –

    – Try to recognise specifically a reload with “performance.navigation.type” but this method is not consistent (and not standard anyway).
    – Try to unbind the ‘beforeunload’ after the ajax finishes and before the redirect to the Thank You page – but WooCommerce has no custom event there (somthing like “beforeredirecttothankyou’) and I couldn’t get to this exact spot with Ajax functions

    I’m trying to understand if it can be done, or core code must be overridden for that.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Melinda

    (@melindahelt)

    Automattic Happiness Engineer

    What you are asking to do is technically possible to a point but the scenario you’re presenting doesn’t have “unsaved changes” which is when this error you are wanting to add would load.

    The form has already been submitted and is processing.

    I found this as a jump off point that might help: https://dev.to/chromiumdev/sure-you-want-to-leavebrowser-beforeunload-event-4eg5

    Plugin Support Mike W

    (@nixiack8)

    Hi @asafmoshejul,

    We have not heard back from you in a while, so I am going to go ahead and close this thread. If you are still experiencing the issue please reply to this thread. Otherwise open a new thread and let us know.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.