I want to make status from "pending" to "completed" after using 100% discount coupon
I've been making a script for my Wordpress site, bc when I use 100% coupon it makes order status "processing" so it won't enroll my courses to user.
I have found this script info functions.php, but it makes all orders, completed. I want to make all orders, which total cart sum is = "0". Can you help me upgrade this code?
/**
* Auto Complete all WooCommerce orders.
*/
if ( WC()->cart->total == 0 ) {
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' );
}
}