I’m working on a site that allows users to customize photo greetings cards. During customization, all photos are stored locally in IndexedDB, then when the user places an order the photos are automatically transferred to the server. That’s working OK, but I made the mistake of doing the transfer in the thankyou.php page after the order is complete. This means that even if the transfer fails the order will still go through.
To fix this I can maybe use a hook that is called right after the ‘place order’ button is clicked, then I can verify the transfer before the order is created. The hook I’m using is woocommerce_review_order_after_submit.
My question is, after I have verified the transfer, how can I stop the order process from continuing if the transfer was unsuccessful? I tried a simple header redirect but that didn’t work.
Edit:
I’m thinking, would it be better to have my own ‘Place Order’ button which does the transfer and verification process and then creates the order programmatically after the verification is complete?
Also, the hook I was using above is the wrong hook. That hook is called when you go to checkout page, which is too soon. I did get the redirect to work though.