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.

You like this post? 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.

Leave a Reply

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