Last active
November 28, 2025 01:57
-
-
Save kish2011/8e9429100efac5b5d1b4d47b0effe911 to your computer and use it in GitHub Desktop.
complete_processing_if_downloadable_and_virtual
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 characters
| <?php | |
| /** | |
| * Plugin Name: Auto Complete Downloadable & Virtual Orders | |
| * Plugin URI: https://example.com | |
| * Description: Automatically marks WooCommerce orders as Completed when all items are Downloadable and Virtual. | |
| * Version: 1.0.0 | |
| * Author: Kishores | |
| * License: GPL2+ | |
| */ | |
| // Exit if accessed directly. | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| /** | |
| * Auto-complete processing orders if all products are downloadable AND virtual | |
| */ | |
| add_action( 'woocommerce_order_status_processing', 'acdv_complete_processing_if_downloadable_and_virtual' ); | |
| function acdv_complete_processing_if_downloadable_and_virtual( $order_id ) { | |
| if ( ! $order_id ) { | |
| return; | |
| } | |
| $order = wc_get_order( $order_id ); | |
| if ( ! $order ) { | |
| return; | |
| } | |
| $downloadable_and_virtual = true; | |
| foreach ( $order->get_items() as $item ) { | |
| $product = $item->get_product(); | |
| // If ANY product is not downloadable OR not virtual → stop | |
| if ( ! $product || ! $product->is_downloadable() || ! $product->is_virtual() ) { | |
| $downloadable_and_virtual = false; | |
| break; | |
| } | |
| } | |
| if ( $downloadable_and_virtual ) { | |
| // Update to completed | |
| $order->update_status( | |
| 'completed', | |
| 'All items are downloadable + virtual — auto-completed by plugin.' | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment