Last active
September 24, 2015 23:15
-
-
Save digitalchild/c4ffa253c3f625653cf6 to your computer and use it in GitHub Desktop.
Auto Complete Paid Orders if all products are 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 | |
| // Place this in theme or your own agency plugin | |
| add_filter( 'woocommerce_payment_complete_order_status', 'complete_paid_orders', 10, 2 ); | |
| /** | |
| * Auto Complete Paid orders in WooCommerce | |
| * only if all products are virtual in the order | |
| * | |
| * @author Jamie Madden <[email protected]> | |
| * @return string order_status | |
| */ | |
| function complete_paid_orders( $order_status, $order_id ) { | |
| $order = new WC_Order( $order_id ); | |
| $order_items = $order->get_items(); | |
| $virtual = false; | |
| foreach ( $order_items as $item ) { | |
| $product = new WC_Product( $item[ 'product_id' ] ); | |
| $virtual = ( $product->is_virtual() ) ? true : false; | |
| } | |
| if ( $virtual ) { | |
| if ( $order_status == 'processing' && ( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) { | |
| return 'completed'; | |
| } | |
| } | |
| return $order_status; | |
| } // complete_paid_orders() | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment