PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
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 / Services / Settings / Checkout_Section.php

Checkout_Section.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.18, at includes/Services/Settings/Checkout_Section.php

156 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checkout Settings Section.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\Services\Settings;
9
10 /**
11 * The Checkout Settings Section: receipt mode, email toggles, and POS
12 * checkout-page asset dequeues.
13 */
14 class Checkout_Section extends Abstract_Section {
15 /**
16 * Section id.
17 */
18 public function id(): string {
19 return 'checkout';
20 }
21
22 /**
23 * Section defaults.
24 */
25 public function defaults(): array {
26 return array(
27 'receipt_default_mode' => 'fiscal',
28 'prevent_overselling' => false,
29 'admin_emails' => array(
30 'enabled' => true,
31 'new_order' => true,
32 'cancelled_order' => true,
33 'failed_order' => true,
34 ),
35 'customer_emails' => array(
36 'enabled' => true,
37 'customer_on_hold_order' => true,
38 'customer_processing_order' => true,
39 'customer_completed_order' => true,
40 'customer_refunded_order' => true,
41 'customer_failed_order' => true,
42 ),
43 'cashier_emails' => array(
44 'enabled' => false,
45 'new_order' => true,
46 ),
47 // this is used in the POS, not in WP Admin (at the moment).
48 'dequeue_script_handles' => array(
49 'admin-bar',
50 'wc-add-to-cart',
51 'wc-stripe-upe-classic',
52 ),
53 'dequeue_style_handles' => array(
54 'admin-bar',
55 'woocommerce-general',
56 'woocommerce-inline',
57 'woocommerce-layout',
58 'woocommerce-smallscreen',
59 'woocommerce-blocktheme',
60 'wp-block-library',
61 ),
62 'disable_wp_head' => false,
63 'disable_wp_footer' => false,
64 );
65 }
66
67 /**
68 * Migrate legacy boolean email settings to array format, in memory only.
69 * The stored boolean becomes the `enabled` flag over the default subkeys.
70 *
71 * @param array $raw Raw option value.
72 */
73 protected function migrate( array $raw ): array {
74 $defaults = $this->defaults();
75 foreach ( array( 'admin_emails', 'customer_emails' ) as $key ) {
76 if ( isset( $raw[ $key ] ) && \is_bool( $raw[ $key ] ) ) {
77 $migrated = $defaults[ $key ];
78 $migrated['enabled'] = $raw[ $key ];
79 $raw[ $key ] = $migrated;
80 }
81 }
82
83 return $raw;
84 }
85
86 /**
87 * Strip the legacy global order_status key on save — but ONLY once its
88 * seed is reflected in the payment_gateways option. Gateway reads are
89 * pure (they apply the legacy seed in memory without persisting), so
90 * stripping earlier would destroy the seed before any payment-gateways
91 * save persists per-gateway statuses, silently reverting them to
92 * defaults on pre-1.9 sites.
93 * This guard can become an unconditional unset once every active site has saved payment-gateways settings under the per-gateway-status schema (post-1.10 migration window).
94 *
95 * @param array $settings Settings about to be saved.
96 */
97 protected function sanitize( array $settings ): array {
98 unset( $settings['auto_print_receipt'], $settings['default_gateway'], $settings['gateways'] );
99 if ( \array_key_exists( 'prevent_overselling', $settings ) ) {
100 $settings['prevent_overselling'] = rest_sanitize_boolean( $settings['prevent_overselling'] );
101 }
102
103 if ( \array_key_exists( 'order_status', $settings ) ) {
104 $gateways_option = get_option( self::DB_PREFIX . 'payment_gateways', array() );
105 $seed_reflected = false;
106 if ( \is_array( $gateways_option ) && isset( $gateways_option['gateways'] ) && \is_array( $gateways_option['gateways'] ) ) {
107 foreach ( $gateways_option['gateways'] as $gateway ) {
108 if ( \is_array( $gateway ) && isset( $gateway['order_status'] ) ) {
109 $seed_reflected = true;
110 break;
111 }
112 }
113 }
114 if ( $seed_reflected ) {
115 unset( $settings['order_status'] );
116 }
117 }
118
119 return $settings;
120 }
121
122 /**
123 * REST endpoint args for checkout updates. Payment-gateway update
124 * validation lives in Payment_Gateways_Section.
125 */
126 public function endpoint_args(): array {
127 return array(
128 'prevent_overselling' => array(
129 'validate_callback' => function ( $param, $request, $key ) {
130 return \is_bool( $param );
131 },
132 ),
133 'receipt_default_mode' => array(
134 'validate_callback' => function ( $param, $request, $key ) {
135 return \is_string( $param ) && \in_array( $param, array( 'fiscal', 'live' ), true );
136 },
137 ),
138 'admin_emails' => array(
139 'validate_callback' => function ( $param, $request, $key ) {
140 return \is_array( $param );
141 },
142 ),
143 'customer_emails' => array(
144 'validate_callback' => function ( $param, $request, $key ) {
145 return \is_array( $param );
146 },
147 ),
148 'cashier_emails' => array(
149 'validate_callback' => function ( $param, $request, $key ) {
150 return \is_array( $param );
151 },
152 ),
153 );
154 }
155 }
156