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/Integrations/WooCommerce_Tax.php +8 -37 1.10.11 → 1.10.20 View file →
@@ -8,9 +8,9 @@
8 8 namespace WCPOS\WooCommercePOS\Integrations;
9 9
10 10 use WC_Abstract_Order;
11 11 use WC_Order;
12 -use WP_REST_Request;
12 +use WCPOS\WooCommercePOS\Services\Order_Write_Intent;
13 13
14 14 /**
15 15 * Keep WooCommerce Tax from restoring stale tax lines onto open POS orders.
16 16 *
@@ -89,26 +89,14 @@
89 89 */
90 90 private $suspended = array();
91 91
92 92 /**
93 - * The order a WCPOS REST write is about to save, and the status it asked for.
94 - *
95 - * WooCommerce's REST controller recalculates totals before it applies the
96 - * requested status, so a request that reopens a paid order and changes its
97 - * lines recalculates while the persisted status is still paid.
98 - *
99 - * @var array{order: WC_Abstract_Order, status: string}|null
100 - */
101 - private $requested = null;
102 -
103 - /**
104 93 * Constructor.
105 94 *
106 - * Suspend at priority 9, before the plugin's snapshot callback at 10; resume
95 + * Prime at 8, suspend at 9 before the plugin's snapshot at 10, then resume
107 96 * from the last priority so nothing re-added runs in the same pass.
108 97 */
109 98 public function __construct() {
110 - add_filter( 'woocommerce_rest_pre_insert_shop_order_object', array( $this, 'note_requested_status' ), 10, 2 );
111 99 add_action( self::BEFORE_HOOK, array( $this, 'prime_tax_rates' ), 8, 2 );
112 100 add_action( self::BEFORE_HOOK, array( $this, 'suspend_tax_preservation' ), 9, 2 );
113 101 add_action( self::AFTER_HOOK, array( $this, 'resume_tax_preservation' ), self::RESUME_PRIORITY );
114 102 }
@@ -113,28 +101,8 @@
113 101 add_action( self::AFTER_HOOK, array( $this, 'resume_tax_preservation' ), self::RESUME_PRIORITY );
114 102 }
115 103
116 104 /**
117 - * Remember the status a REST write asked for, for the recalculation it triggers.
118 - *
119 - * @param mixed $order The order about to be saved.
120 - * @param WP_REST_Request|null $request The request.
121 - *
122 - * @return mixed The order, unchanged.
123 - */
124 - public function note_requested_status( $order, $request = null ) {
125 - $this->requested = null;
126 - if ( $order instanceof WC_Abstract_Order && $request instanceof WP_REST_Request ) {
127 - $this->requested = array(
128 - 'order' => $order,
129 - 'status' => (string) $request->get_param( 'status' ),
130 - );
131 - }
132 -
133 - return $order;
134 - }
135 -
136 - /**
137 105 * Prime the plugin's rates for the order before WooCommerce matches them.
138 106 *
139 107 * Mirrors the request the plugin's protected get_backend_line_items() builds
140 108 * (woocommerce-services 3.6.14), with one deliberate difference: items
@@ -328,8 +296,11 @@
328 296
329 297 /**
330 298 * Whether the order is, or is being put back to, still being built up at the till.
331 299 *
300 + * WooCommerce recalculates totals before applying the requested status, so
301 + * reopening a paid order recalculates while its persisted status is still paid.
302 + *
332 303 * @param WC_Abstract_Order $order The order.
333 304 *
334 305 * @return bool
335 306 */
@@ -337,11 +308,11 @@
337 308 if ( \in_array( $order->get_status(), self::OPEN_STATUSES, true ) ) {
338 309 return true;
339 310 }
340 311
341 - return null !== $this->requested
342 - && $this->requested['order'] === $order
343 - && \in_array( $this->requested['status'], self::OPEN_STATUSES, true );
312 + $intent = Order_Write_Intent::current();
313 + return null !== $intent && $intent->is_subject( $order )
314 + && \in_array( $intent->requested_status(), self::OPEN_STATUSES, true );
344 315 }
345 316
346 317 /**
347 318 * The street line that belongs to the address WooCommerce is taxing.