Thông tin liên hệ

Quốc Trần - Quận Gò Vấp, TP. Hồ Chí Minh

Liên hệ hỗ trợ 0906891294 Zalo
Mạng xã hội
WooCommerce Autocomplete order when used coupon
Cá Mập
  • 02/01/2024
  • Hướng dẫn

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'); } }


Đánh giá bài viết
Cá Mập

Cá Mập code lập trình wordpress, chia sẽ kiến thức, thủ thuật về web wordpress. Liên hệ làm việc 0906 891 294 ( Phone, Zalo )