-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshieldclimb-auto-complete-orders.php
More file actions
80 lines (68 loc) · 2.08 KB
/
shieldclimb-auto-complete-orders.php
File metadata and controls
80 lines (68 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Plugin Name: ShieldClimb – Auto Complete Orders for WooCommerce
* Plugin URI: https://shieldclimb.com/free-woocommerce-plugins/auto-complete-orders/
* Description: Auto Complete Orders for WooCommerce after payment. Works with downloadable & virtual products. Fast, lightweight & compatible with gateways.
* Version: 1.0.4
* Requires Plugins: woocommerce
* Requires at least: 5.8
* Tested up to: 6.9
* WC requires at least: 5.8
* WC tested up to: 10.5.2
* Requires PHP: 7.2
* Author: shieldclimb.com
* Author URI: https://shieldclimb.com/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
/**
* Declare HPOS & Blocks compatibility
*/
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
__FILE__,
true
);
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'cart_checkout_blocks',
__FILE__,
true
);
}
});
add_action(
'woocommerce_order_status_processing',
'shieldclimb_auto_complete_virtual_or_downloadable_order'
);
function shieldclimb_auto_complete_virtual_or_downloadable_order($order_id) {
if (! $order_id) {
return;
}
$order = wc_get_order($order_id);
if (! $order) {
return;
}
$only_virtual_or_downloadable = true;
foreach ($order->get_items() as $item) {
$product = $item->get_product();
if (
! $product ||
(! $product->is_virtual() && ! $product->is_downloadable())
) {
$only_virtual_or_downloadable = false;
break;
}
}
if ($only_virtual_or_downloadable) {
$order->update_status(
'completed',
'Auto-completed by ShieldClimb for virtual/downloadable products.'
);
}
}
?>