-1

I have a WordPress site that sells courses, and I want to make the woocommerce change the order status for the processing to complete.

I tried this https://woocommerce.com/document/automatically-complete-orders/

But when the payment failed, it became complete

I want to make it complete only for the paid courses.

Thank you

KDot
  • 33
  • 7

1 Answers1

2

The reference you picked is ok

https://woocommerce.com/document/automatically-complete-orders/

Just needed a small adjustment:

/**
 * Auto Complete Processing WooCommerce orders on Thankyou Page
 */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) { 
    if ( ! $order_id ) {
        return;
    }

    $order = wc_get_order( $order_id );
    if ( $order->has_status('processing') ) {
        $order->update_status( 'completed' );
    }
   
}

What we are doing with this adjustment is checking if the order has status processing before updating it to completed. This will avoid failed orders to be turned into completed.

Hope it works

Eduhud
  • 208
  • 1
  • 10