Action after confirm payment on WooCommerce

Action after confirm payment on WooCommerce

You need start any action only payment is confirmed? If yes, this post will help you. This a simple but very efficient snippet.

How to create action after payment confirmed on WooCommerce?

Snippet to start specific function after payment is confirmed on WooCommerce. In this example, after payment is confirmed set the new value to user.

function checkPayment ($order_id) {
    
    ///get the order
    $order = new WC_Order($order_id);
    $user_id = $order->get_user_id();

    ///check for set info
    update_user_meta( $user_id, 'field_name', 'field_value' );
    
}

add_action( 'woocommerce_payment_complete', 'checkPayment' );

Important

This Snippet requires the payment method to call woocommerce_payment_complete() / $order->payment_complete(). Most payment methods do this already because is default on woocommerce payment method.

Do you like the post? Please, leave your comment!

Want the latest updates?

Get first-hand access to our plugins updates and news.

Wordpress Developer

Eduardo Villão

Thanks for access my website! I am a Brazilian WordPress developer. Working with programming and WordPress since 2014. Currently developing custom plugins and solutions for WordPress, and work in partnership with companies worldwide.

3 Responses

  1. Olá Eduardo, tudo bom? Estou montando um site em que a pessoa faz uma doação e ganha um número da sorte a cada R$ 50 doados. Após efetuar a doação ela precisa escolher qual produto será doado (2 opções) e qual instituição irá receber aquele produto (2 opções).

    É possível fazer esse fluxo a partir desse snippet que você postou?

    Obrigado,
    Abraços

Leave a Reply

Your email address will not be published. Required fields are marked *