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

Share this:
Share on facebook
Facebook
Share on whatsapp
WhatsApp
Share on email
Email
Share on linkedin
LinkedIn

Leave a Reply

Wordpress Developer
Eduardo Villão

WordPress developer and I live in Brazil. I work with programming and WordPress since 2012. I work in partnership with agencies and companies in the United States, Portugal, Spain, and Brazil.