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
|
<?php // phpcs:ignoreFile
namespace AutomateWoo\Rules;
defined( 'ABSPATH' ) || exit;
/** * @class Order_Shipping_Method */ class Order_Shipping_Method extends Preloaded_Select_Rule_Abstract {
public $data_item = 'order';
public $is_multi = true;
function init() { parent::init();
$this->title = __( 'Order - Shipping Method', 'automatewoo' ); }
/** * @return array */ function load_select_choices() { $choices = [];
foreach ( WC()->shipping()->get_shipping_methods() as $method_id => $method ) { $choices[ $method_id ] = $method->get_method_title(); }
return $choices; }
/** * @param $order \WC_Order * @param $compare * @param $value * @return bool */ function validate( $order, $compare, $value ) {
$methods = [];
foreach( $order->get_shipping_methods() as $shipping_line_item ) { $methods[] = $shipping_line_item->get_method_id(); }
return $this->validate_select( $methods, $compare, $value ); }
}
|