PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
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 / Customer_Writer.php

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

43 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Customer 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\Tax_Id_Writer;
13 use WCPOS\WooCommercePOS\Sync\Order_Write_Payload;
14
15 /** Adapts customer tax IDs and walk-in billing emails around wc/v3. */
16 class Customer_Writer extends Null_Writer {
17 /** Prepare a customer create. */
18 public function prepare_create( array $meta, array $payload, callable $validate_tax_ids ) {
19 $error = $validate_tax_ids( $payload );
20 return is_wp_error( $error ) ? $error : parent::prepare_create( $meta, $this->prepare_payload( $payload ), $validate_tax_ids );
21 }
22
23 /** Prepare a customer update. */
24 public function prepare_update( array $meta, int $id, array $payload, callable $validate_tax_ids ) {
25 $error = $validate_tax_ids( $payload );
26 return is_wp_error( $error ) ? $error : parent::prepare_update( $meta, $id, $this->prepare_payload( $payload ), $validate_tax_ids );
27 }
28
29 /** Persist customer tax IDs after successful writes and poison recovery. */
30 public function persist( string $phase, int $id, array $payload, array $current = array(), array $response_data = array(), array $context = array() ): void {
31 if ( ! in_array( $phase, array( 'create_before_identity', 'create_recovery', 'update' ), true ) || $id <= 0 || ! is_array( $payload['tax_ids'] ?? null ) ) {
32 return;
33 }
34 ( new Tax_Id_Writer() )->write_for_user( $id, $payload['tax_ids'] );
35 }
36
37 /** Remove customer-only fields from the wc/v3 forward. */
38 private function prepare_payload( array $payload ): array {
39 unset( $payload['tax_ids'] );
40 return ( new Order_Write_Payload() )->without_empty_billing_email( $payload );
41 }
42 }
43