PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
← All changes | includes/Admin/Orders/Single_Order.php +29 -0 1.9.16 → 1.10.20 View file →
@@ -7,8 +7,10 @@
7 7
8 8 namespace WCPOS\WooCommercePOS\Admin\Orders;
9 9
10 10 use WC_Abstract_Order;
11 +use WC_Order;
12 +use WCPOS\WooCommercePOS\Services\Order_Notes;
11 13
12 14 /**
13 15 * Single_Order class.
14 16 */
@@ -20,8 +22,9 @@
20 22 public function __construct() {
21 23 add_filter( 'wc_order_is_editable', array( $this, 'wc_order_is_editable' ), 10, 2 );
22 24 add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'add_cashier_select' ) );
23 25 add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_cashier_select' ) );
26 + add_action( 'woocommerce_process_shop_order_meta', array( $this, 'add_customer_change_note' ), 10 );
24 27
25 28 $this->add_available_gateways();
26 29 }
27 30
@@ -128,7 +131,33 @@
128 131 $new_cashier ? $new_cashier->display_name : /* translators: Fallback cashier name shown when the POS cashier user cannot be found. */ __( 'Unknown', 'woocommerce-pos' )
129 132 );
130 133 $order->add_order_note( $note );
131 134 }
135 + }
136 + }
137 +
138 + /**
139 + * Add an audit note before WooCommerce applies its posted customer change.
140 + *
141 + * WooCommerce 10.4.3 registers WC_Meta_Box_Order_Data::save at priority 40;
142 + * this priority-10 callback therefore reads the old customer from the order.
143 + * Core verifies its order-data nonce before firing this hook.
144 + *
145 + * @param int $post_id The order ID.
146 + */
147 + public function add_customer_change_note( $post_id ): void {
148 + // phpcs:disable WordPress.Security.NonceVerification.Missing -- WooCommerce verifies its order-data nonce before firing this hook.
149 + if ( ! array_key_exists( 'customer_user', $_POST ) ) {
150 + return;
151 + }
152 + $order = wc_get_order( $post_id );
153 + if ( ! $order instanceof WC_Order || ! woocommerce_pos_is_pos_order( $order ) ) {
154 + return;
155 + }
156 + $old_customer_id = $order->get_customer_id();
157 + $new_customer_id = absint( wp_unslash( $_POST['customer_user'] ?? 0 ) );
158 + // phpcs:enable WordPress.Security.NonceVerification.Missing
159 + if ( $old_customer_id !== $new_customer_id ) {
160 + Order_Notes::add_admin_customer_change_note( $order, $old_customer_id, $new_customer_id );
132 161 }
133 162 }
134 163 }