PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.16
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.16
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 / Templates / Payment.php

Payment.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.16, at includes/Templates/Payment.php

562 lines 21.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Payment template.
4 *
5 * @author Paul Kilmurray <paul@kilbot.com>
6 *
7 * @see http://wcpos.com
8 * @package WCPOS\WooCommercePOS
9 */
10
11 namespace WCPOS\WooCommercePOS\Templates;
12
13 use Exception;
14 use WCPOS\WooCommercePOS\Services\Settings;
15
16 /**
17 * Payment class.
18 */
19 class Payment {
20 /**
21 * The order ID.
22 *
23 * @var int
24 */
25 private $order_id;
26
27 /**
28 * The gateway ID.
29 *
30 * @phpstan-ignore-next-line
31 * @var string
32 */
33 private $gateway_id;
34
35 /**
36 * The order.
37 *
38 * @var \WC_Order
39 */
40 private $order;
41
42 /**
43 * The coupon nonce.
44 *
45 * @var string
46 */
47 private $coupon_nonce;
48
49 /**
50 * The troubleshooting form nonce.
51 *
52 * @var string
53 */
54 private $troubleshooting_form_nonce;
55
56 /**
57 * Disable wp_head setting.
58 *
59 * @var bool
60 */
61 private $disable_wp_head;
62
63 /**
64 * Disable wp_footer setting.
65 *
66 * @var bool
67 */
68 private $disable_wp_footer;
69
70 /**
71 * Constructor.
72 *
73 * @param int $order_id The order ID.
74 */
75 public function __construct( int $order_id ) {
76 $this->order_id = $order_id;
77 $this->check_troubleshooting_form_submission();
78 // $this->gateway_id = isset( $_GET['gateway'] ) ? sanitize_key( wp_unslash( $_GET['gateway'] ) ) : '';
79
80 $settings_service = Settings::instance();
81 $this->disable_wp_head = (bool) $settings_service->get_settings( 'checkout', 'disable_wp_head' );
82 $this->disable_wp_footer = (bool) $settings_service->get_settings( 'checkout', 'disable_wp_footer' );
83
84 // this is a checkout page.
85 add_filter( 'woocommerce_is_checkout', '__return_true' );
86 // remove the terms and conditions checkbox.
87 add_filter( 'woocommerce_checkout_show_terms', '__return_false' );
88
89 // remove junk from head.
90 add_filter( 'show_admin_bar', '__return_false' );
91 remove_action( 'wp_head', 'rsd_link' );
92 remove_action( 'wp_head', 'wp_generator' );
93 remove_action( 'wp_head', 'feed_links', 2 );
94 remove_action( 'wp_head', 'index_rel_link' );
95 remove_action( 'wp_head', 'wlwmanifest_link' );
96 remove_action( 'wp_head', 'feed_links_extra', 3 );
97 remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
98 remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
99 remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
100 remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
101 remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
102
103 add_action( 'wp_enqueue_scripts', array( $this, 'remove_scripts_and_styles' ), 100 );
104 }
105
106 /**
107 * Each theme will apply its own styles to the checkout page.
108 * I want to keep it simple, so we remove all styles and scripts associated with the active theme.
109 * NOTE: This is not perfect, we don't know the theme handle, so we just take a guess from the source URL.
110 *
111 * @return void
112 */
113 /**
114 * Remove enqueued scripts and styles.
115 *
116 * This function dequeues all scripts and styles that are not specified in the WCPOS settings,
117 * unless they are specifically included by the 'woocommerce_pos_payment_template_dequeue_script_handles'
118 * and 'woocommerce_pos_payment_template_dequeue_style_handles' filters.
119 *
120 * @since 1.3.0
121 */
122 public function remove_scripts_and_styles(): void {
123 global $wp_styles, $wp_scripts;
124
125 /**
126 * List of script handles to exclude from the payment template.
127 *
128 * @since 1.3.0
129 */
130 $script_exclude_list = apply_filters(
131 'woocommerce_pos_payment_template_dequeue_script_handles',
132 woocommerce_pos_get_settings( 'checkout', 'dequeue_script_handles' )
133 );
134
135 /**
136 * List of style handles to exclude from the payment template.
137 *
138 * @since 1.3.0
139 */
140 $style_exclude_list = apply_filters(
141 'woocommerce_pos_payment_template_dequeue_style_handles',
142 woocommerce_pos_get_settings( 'checkout', 'dequeue_style_handles' )
143 );
144
145 // Loop through all enqueued styles and dequeue those that are in the exclusion list.
146 if ( \is_array( $style_exclude_list ) ) {
147 foreach ( $wp_styles->queue as $handle ) {
148 if ( \in_array( $handle, $style_exclude_list, true ) ) {
149 wp_dequeue_style( $handle );
150 }
151 }
152 }
153
154 // Loop through all enqueued scripts and dequeue those that are in the exclusion list.
155 if ( \is_array( $script_exclude_list ) ) {
156 foreach ( $wp_scripts->queue as $handle ) {
157 if ( \in_array( $handle, $script_exclude_list, true ) ) {
158 wp_dequeue_script( $handle );
159 }
160 }
161 }
162 }
163
164
165 /**
166 * Render the payment template.
167 *
168 * @return void
169 */
170 public function get_template(): void {
171 if ( ! \defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
172 \define( 'WOOCOMMERCE_CHECKOUT', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- WooCommerce constant.
173 }
174
175 // if ( ! $this->gateway_id ) {
176 // wp_die( /* translators: Short WCPOS UI label; keep concise. */ esc_html__( 'No gateway selected', 'woocommerce-pos' ) );
177 // }.
178
179 do_action( 'woocommerce_pos_before_pay' );
180
181 try {
182 // initialize order and nonces before the user is switched to customer.
183 $this->initialize_order_and_nonces();
184
185 // Verify order key to prevent unauthenticated access.
186 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Order key is the auth mechanism here, matching WooCommerce core behavior.
187 $provided_key = isset( $_GET['key'] ) ? sanitize_text_field( wp_unslash( $_GET['key'] ) ) : '';
188 if ( ! $provided_key || $provided_key !== $this->order->get_order_key() ) {
189 wp_die(
190 esc_html__( 'Sorry, this order cannot be paid for. The order key is missing or invalid.', 'woocommerce-pos' ),
191 /* translators: Short WCPOS UI label; keep concise. */
192 esc_html__( 'Error', 'woocommerce-pos' ),
193 array( 'response' => 403 )
194 );
195 }
196
197 /*
198 * The wp_set_current_user() function changes the global user object but it does not authenticate the user
199 * for the current session. This means that it will not affect nonce creation or validation because WordPress
200 * nonces are tied to the user's session.
201 *
202 * @TODO - is this the best way to do this?
203 */
204 wp_set_current_user( $this->order->get_customer_id() );
205 add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
206
207 // create nonce for customer
208 // $nonce_field = '<input type="hidden" id="woocommerce-pay-nonce" name="woocommerce-pay-nonce" value="' . $this->create_customer_nonce() . '" />';.
209
210 // Logged in customer trying to pay for someone else's order.
211 if ( ! current_user_can( 'pay_for_order', $this->order_id ) ) {
212 wp_die( esc_html__( 'This order cannot be paid for. Please contact us if you need assistance.', 'woocommerce-pos' ) );
213 }
214
215 // We need to reload the gateways here to use the current customer details.
216 WC()->payment_gateways()->init();
217 $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
218
219 // if ( isset( $available_gateways[ $this->gateway_id ] ) ) {
220 // $gateway = $available_gateways[ $this->gateway_id ];
221 // $gateway->chosen = true;
222 // }.
223
224 $order_button_text = apply_filters( 'woocommerce_pay_order_button_text', /* translators: Short WCPOS UI label; keep concise. */ __( 'Pay for order', 'woocommerce-pos' ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce core hook.
225
226 include woocommerce_pos_locate_template( 'payment.php' );
227 } catch ( Exception $e ) {
228 wc_print_notice( $e->getMessage(), 'error' );
229 }
230 }
231
232 /**
233 * Render the troubleshooting form HTML.
234 *
235 * @return string
236 */
237 public function get_troubleshooting_form_html(): string {
238 global $wp_styles, $wp_scripts;
239 $style_handles = $wp_styles->queue;
240 $script_handles = $wp_scripts->queue;
241
242 $style_exclude_list = apply_filters(
243 'woocommerce_pos_payment_template_dequeue_style_handles',
244 woocommerce_pos_get_settings( 'checkout', 'dequeue_style_handles' )
245 );
246
247 $script_exclude_list = apply_filters(
248 'woocommerce_pos_payment_template_dequeue_script_handles',
249 woocommerce_pos_get_settings( 'checkout', 'dequeue_script_handles' )
250 );
251
252 $merged_style_handles = array_unique( array_merge( $style_handles, $style_exclude_list ) );
253 $merged_script_handles = array_unique( array_merge( $script_handles, $script_exclude_list ) );
254
255 ob_start();
256 ?>
257 <div class="woocommerce-pos-troubleshooting">
258 <div style="text-align:right">
259 <button type="button" class="open-troubleshooting-modal"><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Checkout Settings', 'woocommerce-pos' ); ?></button>
260 </div>
261 <div id="troubleshooting-modal" class="troubleshooting-modal" style="display: none;">
262 <div class="troubleshooting-modal-content">
263 <span class="close-troubleshooting-modal">&times;</span>
264 <form id="troubleshooting-form" method="POST">
265 <p class="woocommerce-info"><?php esc_html_e( 'Scripts and styles may interfere with the custom payment template, use this form to dequeue any problematic scripts.', 'woocommerce-pos' ); ?></p>
266 <div style="margin-bottom: 20px;">
267 <h3><?php esc_html_e( 'Disable All Styles and Scripts', 'woocommerce-pos' ); ?></h3>
268 <label for="disable_wp_head">
269 <input type="checkbox" id="disable_wp_head" name="disable_wp_head" value="1" <?php checked( $this->disable_wp_head ); ?>>
270 <?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Disable wp_head', 'woocommerce-pos' ); ?>
271 </label>
272 <br>
273 <label for="disable_wp_footer">
274 <input type="checkbox" id="disable_wp_footer" name="disable_wp_footer" value="1" <?php checked( $this->disable_wp_footer ); ?>>
275 <?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Disable wp_footer', 'woocommerce-pos' ); ?>
276 </label>
277 </div>
278 <div style="display: flex; justify-content: space-between;margin-bottom:20px;">
279 <div style="flex: 1;">
280 <h3><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Disable Selected Styles', 'woocommerce-pos' ); ?></h3>
281 <?php
282 foreach ( $merged_style_handles as $handle ) {
283 $checked = ! \in_array( $handle, $style_exclude_list, true ) ? 'checked' : '';
284 ?>
285 <input type="checkbox" id="<?php echo esc_attr( $handle ); ?>" name="styles[]" value="<?php echo esc_attr( $handle ); ?>" <?php echo esc_attr( $checked ); ?>>
286 <label for="<?php echo esc_attr( $handle ); ?>"><?php echo esc_html( $handle ); ?></label>
287 <input type="hidden" name="all_styles[]" value="<?php echo esc_attr( $handle ); ?>"><br>
288 <?php } ?>
289 </div>
290 <div style="flex: 1;">
291 <h3><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Disable Selected Scripts', 'woocommerce-pos' ); ?></h3>
292 <?php
293 foreach ( $merged_script_handles as $handle ) {
294 $checked = ! \in_array( $handle, $script_exclude_list, true ) ? 'checked' : '';
295 ?>
296 <input type="checkbox" id="<?php echo esc_attr( $handle ); ?>" name="scripts[]" value="<?php echo esc_attr( $handle ); ?>" <?php echo esc_attr( $checked ); ?>>
297 <label for="<?php echo esc_html( $handle ); ?>"><?php echo esc_html( $handle ); ?></label>
298 <input type="hidden" name="all_scripts[]" value="<?php echo esc_attr( $handle ); ?>"><br>
299 <?php } ?>
300 </div>
301 </div>
302 <input type="hidden" name="troubleshooting_form_nonce" value="<?php echo esc_attr( $this->troubleshooting_form_nonce ); ?>" />
303 <button type="submit"><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Submit', 'woocommerce-pos' ); ?></button>
304 </form>
305 </div>
306 </div>
307 </div>
308
309 <script>
310 document.querySelector('.open-troubleshooting-modal').addEventListener('click', () => {
311 document.getElementById('troubleshooting-modal').style.display = 'block';
312 });
313 document.querySelector('.close-troubleshooting-modal').addEventListener('click', () => {
314 document.getElementById('troubleshooting-modal').style.display = 'none';
315 });
316 window.addEventListener('click', event => {
317 if (event.target === document.getElementById('troubleshooting-modal')) {
318 document.getElementById('troubleshooting-modal').style.display = 'none';
319 }
320 });
321 </script>
322 <?php
323 return ob_get_clean();
324 }
325
326 /**
327 * Render the cashier details HTML.
328 *
329 * @return string
330 */
331 public function get_cashier_details_html(): string {
332 $cashier = $this->order->get_meta( '_pos_user', true );
333 $cashier = get_user_by( 'id', $cashier );
334
335 ob_start();
336 ?>
337 <div class="cashier">
338 <span><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Cashier', 'woocommerce-pos' ); ?>: </span>
339 <span class="cashier-name"><?php echo esc_html( $cashier->display_name ); ?></span>
340 </div>
341 <?php
342 return ob_get_clean();
343 }
344
345 /**
346 * Render the address fields HTML.
347 *
348 * @return string
349 */
350 public function get_paying_customer_details_html(): string {
351 $customer = wp_get_current_user();
352 ob_start();
353 ?>
354 <div class="current-user">
355 <span><?php /* translators: Short WCPOS UI label; keep concise. */ esc_html_e( 'Paying as customer', 'woocommerce-pos' ); ?>: </span>
356 <span class="user-name"><?php echo 0 === $customer->ID ? /* translators: Short WCPOS UI label; keep concise. */ esc_html__( 'Guest', 'woocommerce-pos' ) : esc_html( $customer->display_name ); ?></span>
357 </div>
358 <div class="address-fields" style="display: none;">
359 <section class="woocommerce-customer-details">
360
361 <section class="woocommerce-columns woocommerce-columns--2 woocommerce-columns--addresses col2-set addresses">
362 <div class="woocommerce-column woocommerce-column--1 woocommerce-column--billing-address col-1">
363 <h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
364 <address>
365 <?php echo wp_kses_post( $this->order->get_formatted_billing_address( esc_html__( 'N/A', 'woocommerce' ) ) ); ?>
366 <?php if ( $this->order->get_billing_phone() ) { ?>
367 <p class="woocommerce-customer-details--phone"><?php echo esc_html( $this->order->get_billing_phone() ); ?></p>
368 <?php } ?>
369 <?php if ( $this->order->get_billing_email() ) { ?>
370 <p class="woocommerce-customer-details--email"><?php echo esc_html( $this->order->get_billing_email() ); ?></p>
371 <?php } ?>
372 </address>
373 </div><!-- /.col-1 -->
374
375 <div class="woocommerce-column woocommerce-column--2 woocommerce-column--shipping-address col-2">
376 <h2 class="woocommerce-column__title"><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>
377 <address>
378 <?php echo wp_kses_post( $this->order->get_formatted_shipping_address( esc_html__( 'N/A', 'woocommerce' ) ) ); ?>
379 <?php if ( $this->order->get_shipping_phone() ) { ?>
380 <p class="woocommerce-customer-details--phone"><?php echo esc_html( $this->order->get_shipping_phone() ); ?></p>
381 <?php } ?>
382 </address>
383 </div><!-- /.col-2 -->
384
385 </section><!-- /.col2-set -->
386
387 <?php do_action( 'woocommerce_order_details_after_customer_details', $this->order ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce core hook. ?>
388
389 </section>
390 </div>
391 <script>
392 document.querySelector('.current-user .user-name').addEventListener('click', () => {
393 const addressFields = document.querySelector('.address-fields');
394 addressFields.style.display = addressFields.style.display === 'none' ? 'block' : 'none';
395 });
396 </script>
397 <?php
398 return ob_get_clean();
399 }
400
401 /**
402 * Render the coupon form HTML.
403 *
404 * @return string
405 */
406 public function get_coupon_form_html(): string {
407 ob_start();
408 ?>
409 <div class="coupons">
410 <form method="post" action="">
411 <input type="hidden" name="pos_coupon_nonce" value="<?php echo esc_attr( $this->coupon_nonce ); ?>" />
412 <input type="text" name="pos_coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="pos_coupon_code" value="" />
413 <button type="submit" class="button" name="pos_apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>">
414 <?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?>
415 </button>
416
417 <?php
418 $coupons = $this->order->get_items( 'coupon' );
419 if ( $coupons ) {
420 echo '<h3>' . esc_html__( 'Applied coupons', 'woocommerce' ) . '</h3>';
421 echo '<ul>';
422 foreach ( $coupons as $coupon ) {
423 echo '<li>' . esc_html( $coupon->get_code() ) . ' <button type="submit" class="button" name="pos_remove_coupon" value="' . esc_attr( $coupon->get_code() ) . '">' . esc_html__( 'Remove', 'woocommerce' ) . '</button></li>';
424 }
425 echo '</ul>';
426 }
427 ?>
428 </form>
429 </div>
430 <?php
431 return ob_get_clean();
432 }
433
434 /**
435 * Fix: when checking out as Guest on the desktop application, WordPress gets a $uid from the
436 * session, eg: 't_8b04f8283e7edc5aeee2867c89dd06'. This causes the nonce check to fail.
437 *
438 * @param mixed $uid The user ID.
439 * @param mixed $action The nonce action.
440 */
441 public function nonce_user_logged_out( $uid, $action ) {
442 if ( 'woocommerce-pay' === $action ) {
443 return 0;
444 }
445
446 return $uid;
447 }
448
449 /**
450 * Initialize the order and nonce properties.
451 */
452 private function initialize_order_and_nonces(): void {
453 $this->order = wc_get_order( $this->order_id );
454
455 if ( ! $this->order || $this->order->get_id() !== $this->order_id ) {
456 wp_die( esc_html__( 'Sorry, this order is invalid and cannot be paid for.', 'woocommerce-pos' ) );
457 }
458
459 if ( $this->order->is_paid() ) {
460 wp_die( esc_html__( 'Sorry, this order has already been paid for.', 'woocommerce-pos' ) );
461 }
462
463 $this->coupon_nonce = wp_create_nonce( 'pos_coupon_action' );
464 $this->troubleshooting_form_nonce = wp_create_nonce( 'troubleshooting_form_nonce' );
465 }
466
467 /**
468 * Save the settings from the troubleshooting form.
469 *
470 * @return void
471 */
472 private function check_troubleshooting_form_submission(): void {
473 // Check if our form has been submitted.
474 if ( isset( $_POST['troubleshooting_form_nonce'] ) ) {
475 // Only allow users with manage_woocommerce capability to modify checkout settings.
476 if ( ! current_user_can( 'manage_woocommerce' ) ) {
477 wp_die(
478 esc_html__( 'You do not have permission to modify checkout settings.', 'woocommerce-pos' ),
479 /* translators: Short WCPOS UI label; keep concise. */
480 esc_html__( 'Error', 'woocommerce-pos' ),
481 array( 'response' => 403 )
482 );
483 }
484
485 // Verify the nonce.
486 if ( ! wp_verify_nonce( $_POST['troubleshooting_form_nonce'], 'troubleshooting_form_nonce' ) ) {
487 // Nonce doesn't verify, we should stop execution here.
488 die( 'Nonce value cannot be verified.' );
489 }
490
491 // This will hold your sanitized data.
492 $sanitized_data = array();
493
494 // Sanitize all_styles array.
495 if ( isset( $_POST['all_styles'] ) && \is_array( $_POST['all_styles'] ) ) {
496 $sanitized_data['all_styles'] = array_map( 'sanitize_text_field', wp_unslash( $_POST['all_styles'] ) );
497 }
498
499 // Sanitize styles array.
500 if ( isset( $_POST['styles'] ) && \is_array( $_POST['styles'] ) ) {
501 $sanitized_data['styles'] = array_map( 'sanitize_text_field', wp_unslash( $_POST['styles'] ) );
502 } else {
503 $sanitized_data['styles'] = array(); // consider all styles unchecked if 'styles' is not submitted.
504 }
505
506 // Sanitize all_scripts array.
507 if ( isset( $_POST['all_scripts'] ) && \is_array( $_POST['all_scripts'] ) ) {
508 $sanitized_data['all_scripts'] = array_map( 'sanitize_text_field', wp_unslash( $_POST['all_scripts'] ) );
509 }
510
511 // Sanitize scripts array.
512 if ( isset( $_POST['scripts'] ) && \is_array( $_POST['scripts'] ) ) {
513 $sanitized_data['scripts'] = array_map( 'sanitize_text_field', wp_unslash( $_POST['scripts'] ) );
514 } else {
515 $sanitized_data['scripts'] = array(); // consider all scripts unchecked if 'scripts' is not submitted.
516 }
517
518 // Calculate unchecked styles and scripts.
519 $unchecked_styles = isset( $sanitized_data['all_styles'] ) ? array_diff( $sanitized_data['all_styles'], $sanitized_data['styles'] ) : array();
520 $unchecked_scripts = isset( $sanitized_data['all_scripts'] ) ? array_diff( $sanitized_data['all_scripts'], $sanitized_data['scripts'] ) : array();
521
522 // Sanitize disable_wp_head and disable_wp_footer options.
523 $disable_wp_head = isset( $_POST['disable_wp_head'] ) ? (bool) $_POST['disable_wp_head'] : false;
524 $disable_wp_footer = isset( $_POST['disable_wp_footer'] ) ? (bool) $_POST['disable_wp_footer'] : false;
525
526 // @TODO - the save settings function should allow saving by key
527 $checkout_settings = woocommerce_pos_get_settings( 'checkout' );
528 $new_settings = array_merge(
529 $checkout_settings,
530 array(
531 'disable_wp_head' => $disable_wp_head,
532 'disable_wp_footer' => $disable_wp_footer,
533 'dequeue_style_handles' => $unchecked_styles,
534 'dequeue_script_handles' => $unchecked_scripts,
535 )
536 );
537
538 $settings_service = Settings::instance();
539 $settings_service->save_settings( 'checkout', $new_settings );
540 }
541 }
542
543 /**
544 * Custom version of wp_create_nonce that uses the customer ID.
545 *
546 * @phpstan-ignore-next-line
547 */
548 private function create_customer_nonce() {
549 $user = wp_get_current_user();
550 $uid = (int) $user->ID;
551 // if ( ! $uid ) {
552 // ** This filter is documented in wp-includes/pluggable.php */
553 // $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
554 // }.
555
556 $token = '';
557 $i = wp_nonce_tick();
558
559 return substr( wp_hash( $i . '|woocommerce-pay|' . $uid . '|' . $token, 'nonce' ), - 12, 10 );
560 }
561 }
562