AI Verified

Name

WooCommerce - Autocomplete Virtual Orders

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

TrendoDigital

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

08/07/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommerce - Autocomplete Virtual Orders

 
                    
1add_filter( ‘woocommerce_payment_complete_order_status’, ‘auto_complete_virtual_orders’, 10, 3 );
2 
3function auto_complete_virtual_orders( $payment_complete_status, $order_id, $order ) {
4$current_status = $order->get_status();
5// We only want to update the status to ‘completed’ if it’s coming from one of the following statuses:
6$allowed_current_statuses = array( ‘on-hold’, ‘pending’, ‘failed’ );
7 
8if ( ‘processing’ === $payment_complete_status && in_array( $current_status, $allowed_current_statuses ) ) {
9 
10$order_items = $order->get_items();
11 
12// Create an array of products in the order
13$order_products = array_filter( array_map( function( $item ) {
14// Get associated product for each line item
15return $item->get_product();
16}, $order_items ), function( $product ) {
17// Remove non-products
18return !! $product;
19} );
20 
21if ( count( $order_products > 0 ) ) {
22// Check if each product is ‘virtual’
23$is_virtual_order = array_reduce( $order_products, function( $virtual_order_so_far, $product ) {
24return $virtual_order_so_far && $product->is_virtual();
25}, true );
26 
27if ( $is_virtual_order ) {
28$payment_complete_status = ‘completed’;
29}
30}
31}
32return $payment_complete_status;
33}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

1

Hide Other Shipping Methods When Free Shipping Available

Added: 1 year ago

Last Updated: 1 year ago

Hide Other Shipping Methods When Free Shipping Available

WooCommerce

AI Verified

0

Hide Payment Gateways Based on Cart Total

Added: 2 years ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Change COD default order status to On-hold

Added: 1 year ago

Last Updated: 1 year ago

Makes On-hold the orders using COD and BACS

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

WooCommerce PDF Invoice - Remove all invoices

Added: 1 year ago

Last Updated: 1 year ago

Remove all generated invoices from the plugin WooCommerce PDF Invoice

General

AI Verified

0

Remove Query String - ver

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Hide Fields if Virtual @ WooCommerce Checkout

Added: 1 year ago

Last Updated: 1 year ago