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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / compatibility / WcCheckoutFieldEditor / class-wcml-checkout-field-editor.php
woocommerce-multilingual / compatibility / WcCheckoutFieldEditor Last commit date
Factory.php 2 weeks ago class-wcml-checkout-field-editor.php 2 weeks ago
class-wcml-checkout-field-editor.php
156 lines
1 <?php
2
3 class WCML_Checkout_Field_Editor implements \IWPML_Action {
4
5 protected $package, $billing, $shipping, $additional;
6
7 public function __construct( $package = false ) {
8 $this->package = $package ? $package : (object) [
9 'kind' => 'WooCommerce Add-On',
10 'kind_slug' => 'woocommerce-add-on',
11 'name' => 'checkout-field-editor',
12 'title' => 'WooCommerce Checkout Field Editor',
13 ];
14 }
15
16 public function add_hooks() {
17 global $supress_field_modification;
18 if ( ! is_admin() && ! $supress_field_modification ) {
19 add_filter( 'pre_option_wc_fields_billing', [ $this, 'get_billing' ] );
20 add_filter( 'pre_option_wc_fields_shipping', [ $this, 'get_shipping' ] );
21 add_filter( 'pre_option_wc_fields_additional', [ $this, 'get_additional' ] );
22 }
23 add_filter( 'pre_update_option_wc_fields_billing', [ $this, 'register_fields' ] );
24 add_filter( 'pre_update_option_wc_fields_shipping', [ $this, 'register_fields' ] );
25 add_filter( 'pre_update_option_wc_fields_additional', [ $this, 'register_fields' ] );
26 }
27
28 private function get_exclude_fields() {
29
30 $exclude_fields = [
31 'shipping_address_1',
32 'shipping_city',
33 'shipping_state',
34 'shipping_postcode',
35 'billing_address_1',
36 'billing_city',
37 'billing_state',
38 'billing_postcode',
39 ];
40
41 return apply_filters( 'wcml_cfe_exclude_fields_to_register', $exclude_fields );
42
43 }
44
45 public function register_fields( $fields ) {
46 foreach ( $fields as $string_name => $field ) {
47
48 if ( in_array( $string_name, $this->get_exclude_fields() ) ) {
49 continue;
50 }
51
52 if ( ! empty( $field['label'] ) ) {
53 do_action(
54 'wpml_register_string',
55 $field['label'],
56 "{$string_name}_label",
57 $this->package,
58 "{$string_name} Label",
59 $this->package->kind
60 );
61 }
62 if ( ! empty( $field['placeholder'] ) ) {
63 do_action(
64 'wpml_register_string',
65 $field['placeholder'],
66 "{$string_name}_placeholder",
67 $this->package,
68 "{$string_name} Placeholder",
69 $this->package->kind
70 );
71 }
72 if ( ! empty( $field['options'] ) ) {
73 $i = 1;
74 foreach ( $field['options'] as $option ) {
75 do_action(
76 'wpml_register_string',
77 $option,
78 "{$string_name}_option_{$i}",
79 $this->package,
80 "{$string_name} Option {$i}",
81 $this->package->kind
82 );
83 $i++;
84 }
85 }
86 }
87 return $fields;
88 }
89
90 public function translate_fields( $fields ) {
91 foreach ( $fields as $string_name => &$field ) {
92
93 if ( in_array( $string_name, $this->get_exclude_fields() ) ) {
94 continue;
95 }
96
97 if ( ! empty( $field['label'] ) ) {
98 $field['label'] = apply_filters(
99 'wpml_translate_string',
100 $field['label'],
101 "{$string_name}_label",
102 $this->package
103 );
104 }
105 if ( ! empty( $field['placeholder'] ) ) {
106 $field['placeholder'] = apply_filters(
107 'wpml_translate_string',
108 $field['label'],
109 "{$string_name}_placeholder",
110 $this->package
111 );
112 }
113 if ( ! empty( $field['options'] ) ) {
114 $i = 1;
115 foreach ( $field['options'] as $k => $option ) {
116 $field['options'][ $k ] = apply_filters(
117 'wpml_translate_string',
118 $option,
119 "{$string_name}_option_{$i}",
120 $this->package
121 );
122 $i++;
123 }
124 }
125 }
126 return $fields;
127 }
128
129 public function get_billing() {
130 if ( is_null( $this->billing ) ) {
131 remove_filter( 'pre_option_wc_fields_billing', [ $this, 'get_billing' ] );
132 $this->billing = $this->translate_fields( get_option( 'wc_fields_billing', [] ) );
133 add_filter( 'pre_option_wc_fields_billing', [ $this, 'get_billing' ] );
134 }
135 return $this->billing;
136 }
137
138 public function get_shipping() {
139 if ( is_null( $this->shipping ) ) {
140 remove_filter( 'pre_option_wc_fields_shipping', [ $this, 'get_shipping' ] );
141 $this->shipping = $this->translate_fields( get_option( 'wc_fields_shipping', [] ) );
142 add_filter( 'pre_option_wc_fields_shipping', [ $this, 'get_shipping' ] );
143 }
144 return $this->shipping;
145 }
146
147 public function get_additional() {
148 if ( is_null( $this->additional ) ) {
149 remove_filter( 'pre_option_wc_fields_additional', [ $this, 'get_additional' ] );
150 $this->additional = $this->translate_fields( get_option( 'wc_fields_additional', [] ) );
151 add_filter( 'pre_option_wc_fields_additional', [ $this, 'get_additional' ] );
152 }
153 return $this->additional;
154 }
155 }
156