WOOCOOMERCE: Run function before payment gateway (paying)

In WooCommerce I create orders and users by code and on the ‘order-pay’ endpoint a user is created by form + ajax. The ‘proceed to checkout’ button is disabled by jQuery until the user is created. Now I want to create a server side check. So trying to run a function after submit but before the redirect to the payment gateway.

I’ve tried these hooks but they all don’t work for me in this case (do nothing).

add_action( 'woocommerce_before_checkout_process', 'is_user_created' , 1, 1 );
add_action( 'woocommerce_new_order', 'is_user_created' , 1, 1 );
add_action( 'woocommerce_checkout_process', 'is_user_created' , 1, 1 );
add_action( 'woocommerce_checkout_order_processed', 'is_user_created' , 1, 1 );
add_action( 'woocommerce_check_cart_items', 'is_user_created' , 1, 1 );
add_action( 'woocommerce_review_order_after_submit', 'is_user_created' , 1, 1 );

The function used to test is:

function is_user_created( $order_id ){
    die ('No account created');
}

Any ideas?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Why is it so hard to find a list of woocommerce hooks per page or sequence of execution or order > payment flow?

Anyway, after hours and hours of searching:

add_action( 'woocommerce_before_pay_action', 'Your Function', 1, 1 );

Method 2

This worked for me

add_action( 'woocommerce_before_checkout_process', 'fireBeforeCheckout', 10, 1 );

Method 3

This is the best hook that u can use, this hook launch after last checkout process before redirect user to payment gateway (paying)

add_action( 'woocommerce_checkout_order_processed', 'callback_function' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x