PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.2
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.2
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 / Payments / Checkout_State_Repository.php

Checkout_State_Repository.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.2, at includes/Payments/Checkout_State_Repository.php

55 lines 997 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * POS checkout state repository.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\Payments;
9
10 \defined( 'ABSPATH' ) || die;
11
12 /**
13 * Repository for checkout state.
14 */
15 class Checkout_State_Repository {
16 /**
17 * Order meta key.
18 */
19 private const META_KEY = '_wcpos_checkout_state';
20
21 /**
22 * Persist checkout state on the order.
23 *
24 * @param int $order_id Order ID.
25 * @param array $state State payload.
26 */
27 public function upsert( int $order_id, array $state ): void {
28 $order = wc_get_order( $order_id );
29
30 if ( ! $order ) {
31 return;
32 }
33
34 $order->update_meta_data( self::META_KEY, $state );
35 $order->save_meta_data();
36 }
37
38 /**
39 * Get checkout state for an order.
40 *
41 * @param int $order_id Order ID.
42 */
43 public function get( int $order_id ): array {
44 $order = wc_get_order( $order_id );
45
46 if ( ! $order ) {
47 return array();
48 }
49
50 $state = $order->get_meta( self::META_KEY, true );
51
52 return is_array( $state ) ? $state : array();
53 }
54 }
55