/    Sign up×
Community /Pin to ProfileBookmark

How to stop Woocommerce creating an order if a condition is met?

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.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @simon_matthews spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...