PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
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 1.9.13 1.9.12 1.9.11 1.9.10 1.9.9 All 158 releases
woocommerce-pos / includes / Payments / Checkout_State_Repository.php

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

56 lines 1.0 KB
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 \WCPOS\WooCommercePOS\Sync\Order_Modified_Date::touch( $order_id );
37 }
38
39 /**
40 * Get checkout state for an order.
41 *
42 * @param int $order_id Order ID.
43 */
44 public function get( int $order_id ): array {
45 $order = wc_get_order( $order_id );
46
47 if ( ! $order ) {
48 return array();
49 }
50
51 $state = $order->get_meta( self::META_KEY, true );
52
53 return is_array( $state ) ? $state : array();
54 }
55 }
56