admin管理员组

文章数量:1122832

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 months ago.

Improve this question

Currently I am using woocommerce_thankyou action to run a function that creates an order at a third party service.

However, sometimes customers don't return to the Thank You page after visiting our Payment Service Provider, resulting in no order being created at the third party.

Would it be better to use the woocommerce_order_status_completed action? Any other hooks I could use? Is there a scheme/rundown available somewhere of all the actions that follow eachother? Any other ideas to solve this problem?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 months ago.

Improve this question

Currently I am using woocommerce_thankyou action to run a function that creates an order at a third party service.

However, sometimes customers don't return to the Thank You page after visiting our Payment Service Provider, resulting in no order being created at the third party.

Would it be better to use the woocommerce_order_status_completed action? Any other hooks I could use? Is there a scheme/rundown available somewhere of all the actions that follow eachother? Any other ideas to solve this problem?

Share Improve this question asked Feb 19, 2019 at 10:37 KevsterinoKevsterino 111 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

If you want to send data to third party service, then you want to trust this connection.

So using Thank You page isn't the best idea.

There are some hooks that you may want to check and which of them will be the best for you depends on what exactly are you trying to achieve...

You can use:

  • woocommerce_new_order - it takes $order_id as first param and it's called whenever a new order is placed in WC.

  • woocommerce_order_status_<status> - it also takes $order_id as first param and it will be called when the order changes status to (you can use processing, completed and so on as ).

Using the woocommerce_order_status_completed action might indeed be a better approach compared to relying solely on the woocommerce_thankyou action. The reason is that the woocommerce_order_status_completed action is triggered when an orders status changes to completed , which typically happens after a successful payment.

add_action( 'woocommerce_order_status_completed', 'my_custom_function_to_create_order', 10, 1 );

function my_custom_function_to_create_order( $order_id ) {
    // Get the order object
    $order = wc_get_order( $order_id );

    // Check if the order exists and is valid
    if ( ! $order ) {
        return;
    }

    // Proceed to create order at third-party service
    // Your code to create order at the third-party service
}

本文标签: woocommerce offtopicHook to use when customer placing order