7
7
class Single_Order {
8
8
public function __construct () {
9
9
add_filter ( 'wc_order_is_editable ' , array ( $ this , 'wc_order_is_editable ' ), 10 , 2 );
10
- add_action ('woocommerce_admin_order_data_after_order_details ' , array ( $ this , 'add_cashier_select ' ) );
11
- add_action ('woocommerce_process_shop_order_meta ' , array ( $ this , 'save_cashier_select ' ) );
10
+ add_action ( 'woocommerce_admin_order_data_after_order_details ' , array ( $ this , 'add_cashier_select ' ) );
11
+ add_action ( 'woocommerce_process_shop_order_meta ' , array ( $ this , 'save_cashier_select ' ) );
12
12
}
13
13
14
14
/**
@@ -32,22 +32,22 @@ public function wc_order_is_editable( bool $is_editable, WC_Order $order ): bool
32
32
*/
33
33
public function add_cashier_select ( WC_Order $ order ): void {
34
34
// only show if order created by POS
35
- if ( 'woocommerce-pos ' !== $ order ->get_created_via ()) {
35
+ if ( 'woocommerce-pos ' !== $ order ->get_created_via () ) {
36
36
return ;
37
37
}
38
-
39
- $ cashier_id = $ order ->get_meta ('_pos_user ' );
38
+
39
+ $ cashier_id = $ order ->get_meta ( '_pos_user ' );
40
40
41
41
// Create nonce for security
42
- wp_nonce_field ('pos_cashier_select_action ' , 'pos_cashier_select_nonce ' );
42
+ wp_nonce_field ( 'pos_cashier_select_action ' , 'pos_cashier_select_nonce ' );
43
43
44
44
echo '<p class="form-field form-field-wide"> ' ;
45
45
echo '<label for="_pos_user"> ' . esc_html__ ( 'POS Cashier ' , 'woocommerce-pos ' ) . ':</label> ' ;
46
- echo '<select class="wc-customer-search" id="_pos_user" name="_pos_user" data-placeholder=" ' . esc_attr__ ('Search for a cashier… ' , 'woocommerce-pos ' ) . '" data-allow_clear="true" style="width: 100%;"> ' ;
47
- if ($ cashier_id ) {
48
- $ user = get_user_by ('id ' , $ cashier_id );
49
- if ($ user ) {
50
- echo '<option value=" ' . esc_attr ($ user ->ID ) . '" ' . selected (true , true , false ) . '> ' . esc_html ($ user ->display_name . ' (# ' . $ user ->ID . ' – ' . $ user ->user_email ) . ')</option> ' ;
46
+ echo '<select class="wc-customer-search" id="_pos_user" name="_pos_user" data-placeholder=" ' . esc_attr__ ( 'Search for a cashier… ' , 'woocommerce-pos ' ) . '" data-allow_clear="true" style="width: 100%;"> ' ;
47
+ if ( $ cashier_id ) {
48
+ $ user = get_user_by ( 'id ' , $ cashier_id );
49
+ if ( $ user ) {
50
+ echo '<option value=" ' . esc_attr ( $ user ->ID ) . '" ' . selected ( true , true , false ) . '> ' . esc_html ( $ user ->display_name . ' (# ' . $ user ->ID . ' – ' . $ user ->user_email ) . ')</option> ' ;
51
51
}
52
52
}
53
53
echo '</select> ' ;
@@ -61,19 +61,19 @@ public function add_cashier_select( WC_Order $order ): void {
61
61
*/
62
62
public function save_cashier_select ( $ post_id ): void {
63
63
// Security checks
64
- if ( ! isset ($ _POST ['pos_cashier_select_nonce ' ]) || ! wp_verify_nonce ($ _POST ['pos_cashier_select_nonce ' ], 'pos_cashier_select_action ' ) ) {
64
+ if ( ! isset ( $ _POST ['pos_cashier_select_nonce ' ] ) || ! wp_verify_nonce ( $ _POST ['pos_cashier_select_nonce ' ], 'pos_cashier_select_action ' ) ) {
65
65
return ;
66
66
}
67
67
68
68
/**
69
69
* NOTE: HPOS adds a second arg for WC_Order, but we will make it backwards compatible.
70
70
*/
71
- $ order = wc_get_order ($ post_id );
71
+ $ order = wc_get_order ( $ post_id );
72
72
73
73
// Check if $order is instance of WC_Order and $_POST['_pos_user'] is set
74
- if ( $ order instanceof WC_Order && isset ($ _POST ['_pos_user ' ]) ) {
75
- $ new_pos_cashier = (int ) sanitize_text_field ($ _POST ['_pos_user ' ]);
76
- $ current_pos_cashier = (int ) $ order ->get_meta ('_pos_user ' );
74
+ if ( $ order instanceof WC_Order && isset ( $ _POST ['_pos_user ' ] ) ) {
75
+ $ new_pos_cashier = (int ) sanitize_text_field ( $ _POST ['_pos_user ' ] );
76
+ $ current_pos_cashier = (int ) $ order ->get_meta ( '_pos_user ' );
77
77
78
78
// Update meta only if _pos_user has changed
79
79
if ( $ current_pos_cashier !== $ new_pos_cashier ) {
@@ -85,9 +85,9 @@ public function save_cashier_select( $post_id ): void {
85
85
$ new_cashier = get_userdata ( $ new_pos_cashier );
86
86
$ note = sprintf (
87
87
// translators: 1: old POS cashier, 2: new POS cashier
88
- __ ('POS cashier changed from %1$s to %2$s. ' , 'woocommerce-pos ' ),
89
- $ current_cashier ? $ current_cashier ->display_name : __ ('Unknown ' , 'woocommerce-pos ' ),
90
- $ new_cashier ? $ new_cashier ->display_name : __ ('Unknown ' , 'woocommerce-pos ' )
88
+ __ ( 'POS cashier changed from %1$s to %2$s. ' , 'woocommerce-pos ' ),
89
+ $ current_cashier ? $ current_cashier ->display_name : __ ( 'Unknown ' , 'woocommerce-pos ' ),
90
+ $ new_cashier ? $ new_cashier ->display_name : __ ( 'Unknown ' , 'woocommerce-pos ' )
91
91
);
92
92
$ order ->add_order_note ( $ note );
93
93
}
0 commit comments