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
|
<?php // phpcs:ignoreFile
namespace AutomateWoo\Rules;
use AutomateWoo\DataTypes\DataTypes;
defined( 'ABSPATH' ) || exit;
/** * @class Customer_Order_Statuses */ class Customer_Order_Statuses extends Preloaded_Select_Rule_Abstract {
public $data_item = DataTypes::CUSTOMER;
public $is_multi = true;
function init() { parent::init();
$this->title = __( "Customer - Current Order Statuses", 'automatewoo' ); unset( $this->compare_types[ 'matches_all' ] ); }
/** * @return array */ function load_select_choices() { return wc_get_order_statuses(); }
/** * @param $customer \AutomateWoo\Customer * @param $compare * @param $value * @return bool */ function validate( $customer, $compare, $value ) {
$orders = wc_get_orders([ 'type' => 'shop_order', 'customer' => $customer->is_registered() ? $customer->get_user_id() : $customer->get_email(), 'limit' => -1 ]);
$statuses = []; foreach ( $orders as $order ) { /** @var $order \WC_Order */ $statuses[] = 'wc-' . $order->get_status(); }
return $this->validate_select( $statuses, $compare, $value ); }
}
|