PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.8
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.8
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 1.9.14 All 163 releases
woocommerce-pos / includes / API / V2 / Writers / Order_Writer.php

Order_Writer.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.8, at includes/API/V2/Writers/Order_Writer.php

493 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order collection writer.
4 *
5 * @package WCPOS\WooCommercePOS\API\V2\Writers
6 */
7
8 // phpcs:disable Squiz.Commenting, Generic.Commenting -- Lifecycle docblocks are intentionally concise.
9
10 namespace WCPOS\WooCommercePOS\API\V2\Writers;
11
12 use WCPOS\WooCommercePOS\Services\Order_Notes;
13 use WCPOS\WooCommercePOS\Services\Pos_Order_Audit;
14 use WCPOS\WooCommercePOS\Services\Settings as SettingsService;
15 use WCPOS\WooCommercePOS\Services\Stock_Validator;
16 use WCPOS\WooCommercePOS\Services\Tax_Id_Writer;
17 use WCPOS\WooCommercePOS\Sync\Meta_Entry;
18 use WCPOS\WooCommercePOS\Sync\Order_Serializer;
19 use WCPOS\WooCommercePOS\Sync\Order_Write_Payload;
20 use WCPOS\WooCommercePOS\Sync\Pos_Uuid;
21 use WP_Error;
22 use WP_REST_Response;
23 use const WCPOS\WooCommercePOS\VERSION;
24
25 /** Owns order audit, tax, reassignment, hook, note, email, and stock behavior. */
26 class Order_Writer extends Null_Writer {
27 /**
28 * Audit meta recording HOW an order came to be paid (ADR 0035 path 3):
29 * `offline` means the till ASSERTED payment via `set_paid` — no gateway ran.
30 * Server-owned (spoof-stripped via Pos_Order_Audit::SERVER_META_KEYS).
31 */
32 public const PAYMENT_ASSERTED_META = '_pos_payment_asserted';
33 public const PAYMENT_ASSERTED_OFFLINE = 'offline';
34
35 /** @var object Mutation store used for HPOS-safe audit persistence. */
36 private $store;
37
38 /** @var Order_Write_Payload Order forward payload shaper. */
39 private Order_Write_Payload $order_payload;
40
41 /** Construct the order writer. */
42 public function __construct( object $store, ?Order_Write_Payload $order_payload = null ) {
43 $this->store = $store;
44 $this->order_payload = $order_payload ?? new Order_Write_Payload();
45 }
46
47 /** Prepare an order create and its create-only hook policy. */
48 public function prepare_create( array $meta, array $payload, callable $validate_tax_ids ) {
49 $created_gmt = $this->validate_client_created_gmt( $payload );
50 if ( is_wp_error( $created_gmt ) ) {
51 return $created_gmt;
52 }
53 $error = $validate_tax_ids( $payload );
54 if ( is_wp_error( $error ) ) {
55 return $error;
56 }
57 $forward = $payload;
58 $forward['created_via'] = 'woocommerce-pos';
59 unset( $forward['tax_ids'] );
60 if ( isset( $forward['meta_data'] ) && is_array( $forward['meta_data'] ) ) {
61 $forward['meta_data'] = $this->without_pos_audit_meta( $forward );
62 }
63 $meta_data = isset( $payload['meta_data'] ) && is_array( $payload['meta_data'] ) ? $payload['meta_data'] : array();
64 $till_meta = Pos_Order_Audit::till_meta_from_payload( $meta_data );
65 $till_meta['_pos_user'] = (string) get_current_user_id();
66 $till_meta['_pos_user_created'] = $till_meta['_pos_user'];
67 if ( self::asserts_payment( $payload ) ) {
68 // A CREATE carrying set_paid IS the payment event — the push itself
69 // marks the fresh order paid with no gateway involved.
70 $till_meta[ self::PAYMENT_ASSERTED_META ] = self::PAYMENT_ASSERTED_OFFLINE;
71 }
72 return array(
73 'method' => 'POST',
74 'route' => $meta['route'],
75 'payload' => $this->order_payload->for_create( $forward ),
76 'context' => array(
77 'operation' => 'create',
78 'created_gmt' => $created_gmt,
79 'fill_meta' => $till_meta,
80 ),
81 );
82 }
83
84 /** Prepare an order update and its update-only hook/reassignment policy. */
85 public function prepare_update( array $meta, int $id, array $payload, callable $validate_tax_ids ) {
86 $error = $validate_tax_ids( $payload );
87 if ( is_wp_error( $error ) ) {
88 return $error;
89 }
90 return array(
91 'method' => 'PUT',
92 'route' => $meta['route'] . '/' . $id,
93 'payload' => $payload,
94 'context' => array(),
95 'context_factory' => function () use ( $id, $payload ) {
96 return $this->prepare_order_update_after_read( $id, $payload );
97 },
98 );
99 }
100
101 /** Whether the push payload asserts payment via wc/v3's write-only set_paid flag. */
102 private static function asserts_payment( array $payload ): bool {
103 return isset( $payload['set_paid'] ) && rest_sanitize_boolean( $payload['set_paid'] );
104 }
105
106 /** Repair an existing born-twice order without inventing a version stamp. */
107 public function validate_existing_create( int $id, array $payload, array $prepared ) {
108 // The repair runs against an EXISTING order: if a gateway paid it between
109 // the two create arrivals, the replayed set_paid no longer describes this
110 // order's payment — same needs_payment() guard as the update path. The
111 // recovery phases keep stamping unconditionally: there the order was paid
112 // by this very push.
113 $order = wc_get_order( $id );
114 if ( $order && ! $order->needs_payment() && '' === (string) $order->get_meta( self::PAYMENT_ASSERTED_META ) ) {
115 unset( $payload['set_paid'] );
116 }
117 $this->stamp_order_audit( $id, $payload, false );
118 return null;
119 }
120
121 /** Forward within the named order hook lifecycle. */
122 public function forward( array $prepared, callable $forward ) {
123 return $this->forward_with_reserved_stock( $prepared, $forward );
124 }
125
126 /**
127 * Wrap the create forward in the shared create-pending -> reserve -> complete
128 * sequence, so this lane gets the SAME anti-overselling guarantee as wcpos/v1.
129 *
130 * Without this the only stock check on this lane is the `pre_insert` filter,
131 * which runs against an unsaved order (id 0) and so can only compare
132 * availability — it cannot take a reservation, and two terminals selling the
133 * last unit concurrently both pass it. See Stock_Validator::around_paid_create().
134 *
135 * @param array $prepared Prepared forward.
136 * @param callable $forward Underlying wc/v3 dispatch.
137 */
138 private function forward_with_reserved_stock( array $prepared, callable $forward ) {
139 $context = $prepared['context'];
140 $payload = $prepared['payload'];
141 $paid = isset( $payload['set_paid'] ) && rest_sanitize_boolean( $payload['set_paid'] );
142 $status = isset( $payload['status'] ) ? (string) $payload['status'] : '';
143 $validator = Stock_Validator::instance();
144
145 if ( 'create' !== $context['operation']
146 || ! SettingsService::instance()->prevent_overselling_enabled()
147 || ! $validator->should_validate_create_payload( $status, $paid ) ) {
148 return $this->forward_with_order_lifecycle( $prepared, $forward );
149 }
150
151 $response = null;
152 $order = $validator->around_paid_create(
153 array(
154 'status' => $status,
155 'set_paid' => $paid,
156 'transaction_id' => isset( $payload['transaction_id'] ) ? (string) $payload['transaction_id'] : '',
157 ),
158 function ( array $neutralised ) use ( $prepared, $forward, &$response ) {
159 $prepared['payload']['status'] = $neutralised['status'];
160 $prepared['payload']['set_paid'] = $neutralised['set_paid'];
161 $response = $this->forward_with_order_lifecycle( $prepared, $forward );
162 $data = $response instanceof \WP_REST_Response ? $response->get_data() : null;
163 $id = is_array( $data ) && isset( $data['id'] ) ? (int) $data['id'] : 0;
164
165 return $id > 0 ? wc_get_order( $id ) : $response;
166 }
167 );
168
169 if ( is_wp_error( $order ) ) {
170 return $order;
171 }
172
173 // The controller rebuilds its response document from wc_get_order( $id )
174 // (see document()/build_response_document()), so the forwarded body does
175 // not need re-shaping after payment completes — only the id has to be
176 // right, and it is the same order throughout.
177 return $response;
178 }
179
180 /** Persist the order behavior assigned to a controller-owned protocol phase. */
181 public function persist( string $phase, int $id, array $payload, array $current = array(), array $response_data = array(), array $context = array() ): void {
182 if ( 'create_before_identity' === $phase ) {
183 $this->persist_tax_ids( $id, $payload, true );
184 } elseif ( 'create_after_identity' === $phase ) {
185 $this->stamp_order_audit( $id, $payload, true );
186 $order = wc_get_order( $id );
187 if ( $order ) {
188 Order_Notes::add_creation_note( $order, get_current_user_id(), $order->get_meta( '_pos_store' ) );
189 }
190 } elseif ( 'create_recovery' === $phase ) {
191 $this->stamp_order_audit( $id, $payload, false );
192 $this->persist_tax_ids( $id, $payload, true );
193 } elseif ( 'update' === $phase ) {
194 $this->stamp_order_till_meta( $id, $payload );
195 $this->persist_tax_ids( $id, $payload, false );
196 $this->persist_cashier_store_reassignment( $id, $current, $response_data, $context );
197 if ( ! empty( $context['clear_email'] ) ) {
198 $order = wc_get_order( $id );
199 if ( $order ) {
200 $order->set_billing_email( '' );
201 $order->get_data_store()->update( $order );
202 }
203 }
204 }
205 }
206
207 /** Execute delete with the named stock restore/rollback lifecycle. */
208 public function delete( array $meta, int $id, array $mutation, callable $dispatch, callable $can_delete ) {
209 $force = (bool) ( $mutation['force'] ?? false );
210 return $this->forward_with_stock_restore_rollback(
211 $this->delete_request( $meta['route'] . '/' . $id, $id, $force ),
212 $id,
213 $force,
214 $dispatch,
215 $can_delete
216 );
217 }
218
219 /** Read an order with six-decimal precision and POS links. */
220 public function document( array $meta, int $id, callable $default_document ) {
221 $response = $default_document( $meta, $id, array( 'dp' => '6' ) );
222 $data = $response->get_data();
223 $order = wc_get_order( $id );
224 if ( is_array( $data ) && $order ) {
225 $response->set_data( Order_Serializer::add_pos_links( $data, $order ) );
226 }
227 return $response;
228 }
229
230 /** Build the canonical augmented order response document. */
231 public function build_response_document( array $bare, string $record_id, array $meta, int $id, callable $default_builder ): array {
232 $order = wc_get_order( $id );
233 if ( $order ) {
234 $bare = ( new Order_Serializer() )->document( $bare, Order_Serializer::V2_AUGMENTATIONS, null, $order );
235 }
236 return Pos_Uuid::ensure_in_payload( $bare, $record_id );
237 }
238
239 /** Apply create/update hook policies around one exact forwarded order. */
240 private function forward_with_order_lifecycle( array $prepared, callable $forward ) {
241 $context = $prepared['context'];
242 $forwarded_order = null;
243 $pre_insert = static function ( $order, $request, $creating ) use ( $context, &$forwarded_order ) {
244 $is_create = 'create' === $context['operation'];
245 if ( $is_create && $creating && $order instanceof \WC_Order && null === $forwarded_order ) {
246 $forwarded_order = $order;
247 }
248 $target = $is_create ? ( $creating && $order === $forwarded_order ) : ( $order instanceof \WC_Order && $context['id'] === $order->get_id() );
249 if ( $target ) {
250 foreach ( $context['fill_meta'] as $key => $value ) {
251 $order->update_meta_data( $key, $value );
252 }
253 }
254 if ( $is_create && $creating && null !== $context['created_gmt'] && $order instanceof \WC_Order ) {
255 $order->set_date_created( $context['created_gmt'] );
256 }
257 return $order;
258 };
259 $created_via = static function ( $order ) use ( &$forwarded_order ) {
260 if ( $order instanceof \WC_Order && $order === $forwarded_order && 'woocommerce-pos' !== $order->get_created_via() ) {
261 $order->set_created_via( 'woocommerce-pos' );
262 }
263 };
264 $use_filter = 'create' === $context['operation'] || array() !== $context['fill_meta'];
265 if ( $use_filter ) {
266 add_filter( 'woocommerce_rest_pre_insert_shop_order_object', $pre_insert, 10, 3 );
267 }
268 if ( 'create' === $context['operation'] ) {
269 add_action( 'woocommerce_before_order_object_save', $created_via );
270 }
271 try {
272 return $forward( $prepared['method'], $prepared['route'], $prepared['payload'] );
273 } finally {
274 if ( $use_filter ) {
275 remove_filter( 'woocommerce_rest_pre_insert_shop_order_object', $pre_insert, 10 );
276 }
277 if ( 'create' === $context['operation'] ) {
278 remove_action( 'woocommerce_before_order_object_save', $created_via );
279 }
280 }
281 }
282
283 /** Name and execute the permanent/trash stock restore/rollback protocol. */
284 private function forward_with_stock_restore_rollback( $request, int $id, bool $force, callable $dispatch, callable $can_delete ) {
285 $setting = SettingsService::instance()->restore_stock_on_delete_enabled();
286 $restore_stock = apply_filters( 'woocommerce_pos_restore_stock_on_delete', $setting, $id );
287 $pre_restored = false;
288 if ( $restore_stock && $force && $this->order_stock_reduced( $id ) && $can_delete( $id ) ) {
289 wc_maybe_increase_stock_levels( $id );
290 $pre_restored = true;
291 }
292 $response = $dispatch( $request );
293 if ( $response->get_status() >= 400 ) {
294 if ( $pre_restored ) {
295 wc_maybe_reduce_stock_levels( $id );
296 }
297 return new WP_REST_Response( $response->get_data(), $response->get_status() );
298 }
299 if ( $restore_stock && ! $force ) {
300 wc_maybe_increase_stock_levels( $id );
301 }
302 return $response;
303 }
304
305 /** Capture and authorize the cashier/store reassignment lifecycle. */
306 private function prepare_order_update_after_read( int $id, array $payload ): array {
307 $reassignment = array();
308 foreach ( is_array( $payload['meta_data'] ?? null ) ? $payload['meta_data'] : array() as $entry ) {
309 $key = Meta_Entry::key( $entry );
310 if ( is_scalar( $key ) && in_array( (string) $key, array( '_pos_user', '_pos_store' ), true ) ) {
311 $reassignment[ (string) $key ] = Meta_Entry::value( $entry ) ?? '';
312 }
313 }
314 $authorized = isset( $reassignment['_pos_store'] ) && is_scalar( $reassignment['_pos_store'] ) && '' !== (string) $reassignment['_pos_store']
315 ? (bool) apply_filters( 'woocommerce_pos_order_store_reassignment_allowed', true, (string) $reassignment['_pos_store'], $id )
316 : false;
317 $forward = $payload;
318 unset( $forward['created_via'], $forward['tax_ids'] );
319 if ( isset( $forward['meta_data'] ) && is_array( $forward['meta_data'] ) ) {
320 $forward['meta_data'] = $this->without_pos_audit_meta( $forward, $id );
321 }
322 $clear_email = isset( $forward['billing'] ) && is_array( $forward['billing'] )
323 && array_key_exists( 'email', $forward['billing'] ) && '' === $forward['billing']['email'];
324 $fill_meta = array();
325 $pre_store = null;
326 $order = wc_get_order( $id );
327 if ( $order ) {
328 /*
329 * `set_paid` is write-only in wc/v3, so a client re-sends it on every
330 * later edit of an order it created offline. WooCommerce only takes
331 * payment on update when the order still needs it (`$creating ||
332 * needs_payment()` in its orders controller) — mirror that, pre-forward,
333 * or an update to an order ALREADY paid by a real gateway (hosted pay
334 * page) would stamp 'offline' over a gateway-taken payment: the exact
335 * distinction this marker exists to draw. Fill-only, never overwrite.
336 */
337 if ( self::asserts_payment( $payload ) && $order->needs_payment() && '' === (string) $order->get_meta( self::PAYMENT_ASSERTED_META ) ) {
338 $fill_meta[ self::PAYMENT_ASSERTED_META ] = self::PAYMENT_ASSERTED_OFFLINE;
339 }
340 $pre_store = (string) $order->get_meta( '_pos_store' );
341 foreach ( array( '_pos_user', '_pos_user_created' ) as $key ) {
342 if ( '' === (string) $order->get_meta( $key ) ) {
343 $fill_meta[ $key ] = (string) get_current_user_id();
344 }
345 }
346 $till = Pos_Order_Audit::till_meta_from_payload( is_array( $payload['meta_data'] ?? null ) ? $payload['meta_data'] : array() );
347 foreach ( Pos_Order_Audit::cash_meta_keys() as $key ) {
348 if ( isset( $till[ $key ] ) && '' === (string) $order->get_meta( $key ) ) {
349 $fill_meta[ $key ] = $till[ $key ];
350 }
351 }
352 if ( $authorized && (string) $order->get_meta( '_pos_store' ) !== (string) $reassignment['_pos_store'] ) {
353 $fill_meta['_pos_store'] = (string) $reassignment['_pos_store'];
354 }
355 }
356 return array(
357 'payload' => $this->order_payload->for_update( $id, $forward ),
358 'context' => array(
359 'operation' => 'update',
360 'id' => $id,
361 'clear_email' => $clear_email,
362 'reassignment' => $reassignment,
363 'store_authorized' => $authorized,
364 'pre_store' => $pre_store,
365 'fill_meta' => $fill_meta,
366 ),
367 );
368 }
369
370 /** Persist reassignment and its mutually exclusive order-note policy. */
371 private function persist_cashier_store_reassignment( int $id, array $current, array $data, array $context ): void {
372 $order = wc_get_order( $id );
373 if ( ! $order || ! is_array( $data ) ) {
374 return;
375 }
376 $current_user = get_current_user_id();
377 $change = $context['reassignment'];
378 $old_user = $order->get_meta( '_pos_user' );
379 $old_store = null !== $context['pre_store'] ? $context['pre_store'] : $order->get_meta( '_pos_store' );
380 $cashier_changed = isset( $change['_pos_user'] ) && is_numeric( $change['_pos_user'] )
381 && (int) $change['_pos_user'] === $current_user && (string) $old_user !== (string) $current_user;
382 $store_changed = $context['store_authorized'] && (string) $old_store !== (string) $change['_pos_store'];
383 if ( $cashier_changed ) {
384 $order->update_meta_data( '_pos_user', (string) $current_user );
385 }
386 if ( $store_changed ) {
387 $order->update_meta_data( '_pos_store', (string) $change['_pos_store'] );
388 }
389 if ( $cashier_changed || $store_changed ) {
390 $order->save();
391 }
392 if ( 'pos-open' === ( $data['status'] ?? '' ) && 'pos-open' !== ( $current['status'] ?? '' ) ) {
393 Order_Notes::add_reopen_note( $order, $current_user, $order->get_meta( '_pos_store' ) );
394 } else {
395 if ( $cashier_changed ) {
396 Order_Notes::add_cashier_change_note( $order, $old_user, $current_user );
397 }
398 if ( $store_changed ) {
399 Order_Notes::add_store_change_note( $order, $old_store, $change['_pos_store'] );
400 }
401 }
402 if ( array_key_exists( 'customer_id', $current ) && array_key_exists( 'customer_id', $data ) && (int) $current['customer_id'] !== (int) $data['customer_id'] ) {
403 Order_Notes::add_pos_customer_change_note( $order, $current['customer_id'], $data['customer_id'] );
404 }
405 }
406
407 /** Persist order tax IDs or the create-time customer snapshot. */
408 private function persist_tax_ids( int $id, array $payload, bool $is_create ): void {
409 $order = wc_get_order( $id );
410 if ( ! $order ) {
411 return;
412 }
413 if ( is_array( $payload['tax_ids'] ?? null ) ) {
414 ( new Tax_Id_Writer() )->write_for_order( $order, $payload['tax_ids'] );
415 } elseif ( $is_create && $order->get_customer_id() > 0 ) {
416 ( new Tax_Id_Writer() )->snapshot_from_user_to_order( $order, $order->get_customer_id() );
417 }
418 }
419
420 /** Persist server-owned order audit metadata. */
421 private function stamp_order_audit( int $id, array $payload, bool $stamp_version ): void {
422 $meta = array( '_pos_user' => (string) get_current_user_id() );
423 // Create-shaped phases only (create_after_identity, create_recovery, the
424 // born-twice repair): the create push itself asserted the payment, so no
425 // needs_payment() gate — by the time this runs post-forward the order is
426 // already paid BY THIS PUSH. The update path carries its own guard.
427 if ( self::asserts_payment( $payload ) ) {
428 $meta[ self::PAYMENT_ASSERTED_META ] = self::PAYMENT_ASSERTED_OFFLINE;
429 }
430 if ( $stamp_version ) {
431 $meta['_woocommerce_pos_version'] = VERSION;
432 $meta['_pos_user_created'] = $meta['_pos_user'];
433 }
434 $payload_meta = is_array( $payload['meta_data'] ?? null ) ? $payload['meta_data'] : array();
435 $this->store->persist_order_audit_meta( $id, array_merge( $meta, Pos_Order_Audit::till_meta_from_payload( $payload_meta ) ), 'woocommerce-pos' );
436 }
437
438 /** Persist missing cash-tender metadata after update. */
439 private function stamp_order_till_meta( int $id, array $payload ): void {
440 $meta = array();
441 foreach ( is_array( $payload['meta_data'] ?? null ) ? $payload['meta_data'] : array() as $entry ) {
442 $key = Meta_Entry::key( $entry );
443 $value = Meta_Entry::value( $entry ) ?? '';
444 if ( is_scalar( $key ) && in_array( (string) $key, Pos_Order_Audit::cash_meta_keys(), true ) && is_scalar( $value ) && '' !== (string) $value ) {
445 $meta[ (string) $key ] = (string) $value;
446 }
447 }
448 if ( $meta ) {
449 $this->store->persist_order_audit_meta( $id, $meta );
450 }
451 }
452
453 /** Strip server-owned audit metadata from a forward. */
454 private function without_pos_audit_meta( array $payload, int $id = 0 ): array {
455 $meta = is_array( $payload['meta_data'] ?? null ) ? $payload['meta_data'] : array();
456 $protected = $id > 0 ? Pos_Order_Audit::audit_meta_ids( wc_get_order( $id ) ) : array();
457 return Pos_Order_Audit::strip_audit_meta( $meta, $protected );
458 }
459
460 /** Validate and normalize the optional client create timestamp. */
461 private function validate_client_created_gmt( array $payload ) {
462 if ( ! isset( $payload['date_created_gmt'] ) ) {
463 return null;
464 }
465 if ( ! is_scalar( $payload['date_created_gmt'] ) ) {
466 return $this->invalid_created_gmt();
467 }
468 $value = wc_clean( wp_unslash( (string) $payload['date_created_gmt'] ) );
469 if ( '' === $value ) {
470 return null;
471 }
472 $timestamp = 1 === preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?$/i', $value )
473 ? rest_parse_date( 'Z' === strtoupper( substr( $value, -1 ) ) ? $value : $value . 'Z', true ) : false;
474 if ( false === $timestamp ) {
475 return $this->invalid_created_gmt();
476 }
477 return $timestamp > time() + DAY_IN_SECONDS
478 ? new WP_Error( 'woocommerce_pos_rest_future_date_created_gmt', __( 'date_created_gmt cannot be more than 24 hours in the future.', 'woocommerce-pos' ), array( 'status' => 400 ) )
479 : $timestamp;
480 }
481
482 /** Build the stable invalid create timestamp error. */
483 private function invalid_created_gmt(): WP_Error {
484 return new WP_Error( 'woocommerce_pos_rest_invalid_date_created_gmt', __( 'date_created_gmt must be a valid ISO 8601 UTC date.', 'woocommerce-pos' ), array( 'status' => 400 ) );
485 }
486
487 /** Whether order stock was actually reduced before delete. */
488 private function order_stock_reduced( int $id ): bool {
489 $order = wc_get_order( $id );
490 return $order instanceof \WC_Order && (bool) $order->get_data_store()->get_stock_reduced( $id );
491 }
492 }
493