auto complete order 1

auto complete order

/**
 * Auto Complete all WooCommerce orders.
 */
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 );
    $order->update_status( 'completed' );
}

Here is what the above code is Doing:
1. We’re hooking into the woocommerce_thankyou action.
2. We’re checking if the order ID is empty.
3. We’re getting the order object.
4. We’re updating the order status to completed.

Similar Posts