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
|
<?php
namespace AutomateWoo;
defined( 'ABSPATH' ) || exit;
/** * @class Variable_Order_Shipping_Method */ class Variable_Order_Shipping_Method extends Variable {
/** * Load admin details. */ public function load_admin_details() { $this->add_parameter_select_field( 'format', __( 'Choose whether to display the title or the ID of the shipping method.', 'automatewoo' ), [ '' => __( 'Title', 'automatewoo' ), 'id' => __( 'ID', 'automatewoo' ), ], false );
$this->description = __( 'Displays the shipping method for the order.', 'automatewoo' ); }
/** * @param \WC_Order $order * @param array $parameters * @return string */ public function get_value( $order, $parameters ) {
$display = isset( $parameters['format'] ) ? $parameters['format'] : 'title';
switch ( $display ) { case 'id': // get id of first method $methods = $order->get_shipping_methods(); $method = current( $methods ); return $method->get_method_id(); case 'title': return $order->get_shipping_method(); } } }
|