0

WooCommerce auto complete orders which has products marked as virtual & downloadable type.. while it puts orders into processing not complete status if its a virtual product only.

What if we need to auto complete orders with virtual products too instead of putting it in processing ?

We found this but it auto completes all orders not just the virtual products

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

We need to auto complete the orders have virtual products as it happens for the orders with products marked as virtual & downlodable

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
Maged Mohamed
  • 511
  • 5
  • 27
  • Duplicate: [Change order status for virtual, downloadable, free or backorder products in WooCommerce](https://stackoverflow.com/questions/61371178/change-order-status-for-virtual-downloadable-free-or-backorder-products-in-woo) – 7uc1f3r Jun 08 '20 at 07:08
  • @7uc1f3r does that work only for free orders ?, i mean when the order total is 0 ?.. what we want is when order total is 0 & products in order is virtual then set the status to completed instead of processing .. is that the case ? – Maged Mohamed Jun 08 '20 at 08:47
  • Nothing prevents you from further adapting the code to your wishes. In the end, not every answer you can find here is 100% what you are looking for, but this is the intention from SO, that you can learn from it. The example I share should definitely enable you to get the result you are looking for, therefore I see it as a duplicate question. – 7uc1f3r Jun 08 '20 at 08:50
  • Yes sir i got it .. but i just need to make sure that it works for free orders only not orders with payment methods right ? – Maged Mohamed Jun 08 '20 at 08:52
  • You can always check for additional conditions such as `$order_total`. All information about obtaining order information can be found [here](https://stackoverflow.com/questions/39401393/how-to-get-woocommerce-order-details) – 7uc1f3r Jun 08 '20 at 08:55

0 Answers0