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

Tax_Id_Settings.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.14, at includes/Services/Tax_Id_Settings.php

76 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tax ID Settings.
4 *
5 * Centralises the Tax-ID-related settings: per-type write-map overrides plus
6 * the capture/display toggles surfaced in the admin SPA. Values come from
7 * WCPOS settings (the top-level `tax_ids` section, allowing the existing
8 * settings service to handle persistence) and fall back to sensible defaults.
9 *
10 * @package WCPOS\WooCommercePOS
11 */
12
13 namespace WCPOS\WooCommercePOS\Services;
14
15 /**
16 * Tax_Id_Settings class.
17 */
18 class Tax_Id_Settings {
19 /**
20 * Default per-type → meta-key write map.
21 *
22 * `_billing_vat_number` is the WC EU VAT Number current key and is read
23 * out-of-the-box by most VAT-aware plugins, so we use it as the catch-all
24 * for VAT-shaped types when no plugin and no override are present.
25 *
26 * @return array<string,string>
27 */
28 public static function default_write_map(): array {
29 return array(
30 Tax_Id_Types::TYPE_EU_VAT => '_billing_vat_number',
31 Tax_Id_Types::TYPE_GB_VAT => '_billing_vat_number',
32 Tax_Id_Types::TYPE_SA_VAT => '_billing_vat_number',
33 Tax_Id_Types::TYPE_AU_ABN => '_billing_vat_number',
34 Tax_Id_Types::TYPE_CA_GST_HST => '_billing_vat_number',
35 Tax_Id_Types::TYPE_US_EIN => '_billing_vat_number',
36 Tax_Id_Types::TYPE_OTHER => '_billing_vat_number',
37 Tax_Id_Types::TYPE_BR_CPF => '_billing_cpf',
38 Tax_Id_Types::TYPE_BR_CNPJ => '_billing_cnpj',
39 Tax_Id_Types::TYPE_IN_GST => '_billing_gstin',
40 Tax_Id_Types::TYPE_IT_CF => '_billing_cf',
41 Tax_Id_Types::TYPE_IT_PIVA => '_billing_piva',
42 Tax_Id_Types::TYPE_ES_NIF => '_billing_nif',
43 Tax_Id_Types::TYPE_AR_CUIT => '_billing_cuit',
44 );
45 }
46
47 /**
48 * User-configured per-type overrides for the write map.
49 *
50 * Reads from the `tax_ids.write_map` settings tree, including the legacy
51 * `general.tax_ids.write_map` fallback provided by Settings. Invalid types
52 * or empty keys are silently dropped.
53 *
54 * @return array<string,string>
55 */
56 public static function get_overrides(): array {
57 $raw = \wcpos_get_settings( 'tax_ids', 'write_map' );
58 if ( ! \is_array( $raw ) ) {
59 $raw = array();
60 }
61
62 $out = array();
63 foreach ( $raw as $type => $meta_key ) {
64 if ( ! \is_string( $type ) || ! Tax_Id_Types::is_valid_type( $type ) ) {
65 continue;
66 }
67 if ( ! \is_string( $meta_key ) || '' === $meta_key ) {
68 continue;
69 }
70 $out[ $type ] = $meta_key;
71 }
72
73 return $out;
74 }
75 }
76