Last active
January 22, 2025 21:41
-
-
Save Acephalia/873f1a6c13e842a8c62aa73a1b976231 to your computer and use it in GitHub Desktop.
Revisions
-
Acephalia revised this gist
Jan 10, 2024 . 1 changed file with 10 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,28 @@ // Auto-complete virtual orders if payment is completed by u/acephaliax function auto_complete_virtual_orders($order_id) { if (!$order_id) { return; } // Get the order object $order = wc_get_order($order_id); // Check if the order contains virtual products $contains_virtual = false; foreach ($order->get_items() as $item) { $product = $item->get_product(); if ($product && $product->is_virtual()) { $contains_virtual = true; break; } } // Check if the payment is completed $payment_completed = $order->is_paid(); // If the order contains virtual products and the payment is completed, auto-complete it if ($contains_virtual && $payment_completed) { $order->update_status('completed'); } } -
Acephalia revised this gist
Aug 23, 2023 . 1 changed file with 25 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,40 +1,28 @@ /** * Auto-complete virtual orders. */ function auto_complete_virtual_orders($order_id) { if (!$order_id) { return; } // Get the order object $order = wc_get_order($order_id); // Check if the order contains virtual products $contains_virtual = false; foreach ($order->get_items() as $item) { $product = $item->get_product(); if ($product && $product->is_virtual()) { $contains_virtual = true; break; } } // If the order contains virtual products, auto-complete it if ($contains_virtual) { $order->update_status('completed'); } } add_action('woocommerce_order_status_changed', 'auto_complete_virtual_orders', 10, 3); -
Acephalia created this gist
Mar 17, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ add_action('woocommerce_thankyou', 'virtual_orders_that_cleanup_after_themselves', 10, 1 ); function virtual_orders_that_cleanup_after_themselves( $order_id ) { if( ! $order_id ) return; // Get order $order = wc_get_order( $order_id ); // get order items = each product in the order $items = $order->get_items(); // Set variable $only_virtual = true; foreach ( $items as $item ) { // Get product id $product = wc_get_product( $item['product_id'] ); // Is virtual $is_virtual = $product->is_virtual(); // Is_downloadable $is_downloadable = $product->is_downloadable(); if ( ! $is_virtual && ! $is_downloadable ) { $only_virtual = false; } } // true if ( $only_virtual ) { $order->update_status( 'completed' ); } }