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?
The cart is no longer relevant after the order is created, so you need to check the order total inside the function and act based on that. Your code should looks something like this:
How to add WooCommerce Autocomplete order when used coupon
Code here in function :
add_action('woocommerce_checkout_order_processed', '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->get_total() == 0) { $order->update_status('completed'); } }