PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.3
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.3
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / elementor / modules / checkout / fields / select.php

select.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.2.3, at includes/elementor/modules/checkout/fields/select.php

231 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Elementor\Modules\Checkout\Fields;
4
5 defined( 'ABSPATH' ) || die();
6
7 use Sellkit\Elementor\Modules\Checkout\Fields\Base;
8
9 /**
10 * Class select.
11 *
12 * @since 1.1.0
13 * @SuppressWarnings(PHPMD.NPathComplexity)
14 */
15 class Select extends Base {
16 /**
17 * Type of field.
18 *
19 * @return string
20 * @since 1.1.0
21 */
22 public function type() {
23 return 'select';
24 }
25
26 /**
27 * Adds additional class for fields if required.
28 *
29 * @param array $args checkout fields options.
30 * @param string $key field key.
31 * @return array
32 * @since 1.1.0
33 */
34 protected function additional_class( $args, $key ) {
35 $args['class'][] = 'country-state';
36
37 $country_key = 'sellkit-checkout-shipping-cc';
38
39 if ( 'billing_state' === $key ) {
40 $country_key = 'sellkit-checkout-billing-cc';
41 }
42
43 $country_code = sellkit_htmlspecialchars( INPUT_COOKIE, $country_key );
44
45 $states = WC()->countries->get_states( $country_code );
46
47 if ( ( 'billing_state' === $key || 'shipping_state' === $key ) && ( ! is_array( $states ) || empty( $states ) ) ) {
48 return $args;
49 }
50
51 $args['class'][] = 'sellkit-checkout-field-select';
52
53 return $args;
54 }
55
56 /**
57 * Customized html per field.
58 *
59 * @param string $field field html string.
60 * @param array $args checkout fields options.
61 * @param string $key key of field.
62 * @return void
63 * @since 1.1.0
64 */
65 public function field( $field, $args, $key ) {
66 echo '<i class="fa fa-angle-down sellkit-select-appearance"></i>';
67
68 if ( 'shipping_country' === $key || 'billing_country' === $key ) {
69 $default = '';
70 if ( array_key_exists( 'default', $args ) ) {
71 $default = $args['default'];
72 }
73
74 $this->woocommerce_field_country( $key, $default );
75
76 return;
77 }
78
79 if ( 'shipping_state' === $key || 'billing_state' === $key ) {
80 $country_code = filter_input( INPUT_COOKIE, 'sellkit-checkout-shipping-cc' );
81
82 if ( 'billing_state' === $key ) {
83 $country_code = filter_input( INPUT_COOKIE, 'sellkit-checkout-billing-cc' );
84 }
85
86 if ( empty( $country_code ) ) {
87 $country_code = 'US';
88 }
89
90 $states = WC()->countries->get_states( $country_code );
91
92 $this->woocommerce_field_state( $key, $args, $states );
93
94 return;
95 }
96 ?>
97 <p id="<?php echo $key; ?>_field">
98 <span class="woocommerce-input-wrapper">
99 <select
100 name="<?php echo esc_attr( $key ); ?>"
101 id="<?php echo esc_attr( $key ); ?>"
102 class=""
103 autocomplete="country"
104 data-placeholder="<?php echo ( array_key_exists( 'label', $args ) ) ? esc_attr( $args['label'] ) : ''; ?>"
105 data-label="<?php echo ( array_key_exists( 'label', $args ) ) ? esc_attr( $args['label'] ) : ''; ?>"
106 >
107 <?php
108 $default_value = ( array_key_exists( 'default', $args ) ) ? $args['default'] : '';
109 ?>
110 <?php foreach ( $args['options'] as $value => $label ) : ?>
111 <?php
112 if ( $value === $default_value ) {
113 echo sprintf(
114 /** Translators: 1:value 2: label */
115 '<option selected value="%1$s">%2$s</option>',
116 esc_attr( $value ),
117 esc_html( $label ),
118 );
119
120 continue;
121 }
122
123 echo sprintf(
124 /** Translators: 1:value 2: label */
125 '<option value="%1$s">%2$s</option>',
126 esc_attr( $value ),
127 esc_html( $label ),
128 );
129 ?>
130 <?php endforeach; ?>
131 </select>
132 </span>
133 </p>
134 <?php
135 }
136
137 /**
138 * Customize woocommerce country field.
139 *
140 * @param string $key field key.
141 * @param string $default field default value.
142 * @since 1.1.0
143 * @return void
144 */
145 private function woocommerce_field_country( $key, $default ) {
146 ?>
147 <p id="<?php echo $key; ?>_field">
148 <span class="woocommerce-input-wrapper">
149 <?php
150 $countries = WC()->countries->get_shipping_countries();
151
152 if ( 'billing_country' === $key ) {
153 $countries = WC()->countries->get_allowed_countries();
154 }
155
156 $field = '<select name="' . esc_attr( $key ) . '" id="' . $key . '" class="country_to_state" ><option value="">' . esc_html__( 'Select a country…', 'sellkit' ) . '</option>';
157
158 foreach ( $countries as $country_key => $country_label ) {
159 $selected = '';
160
161 if ( $default === $country_key ) {
162 $selected = 'selected="selected"';
163 }
164
165 $field .= '<option ' . $selected . ' value="' . esc_attr( $country_key ) . '" >' . esc_html( $country_label ) . '</option>';
166 }
167
168 $field .= '</select>';
169 $field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' . esc_attr__( 'Update country', 'sellkit' ) . '" /></noscript>';
170
171 echo $field;
172 ?>
173 </span>
174 </p>
175 <?php
176 }
177
178 /**
179 * Customize woocommerce state field.
180 *
181 * @param string $key field key.
182 * @param array $args field options.
183 * @param array $states country states.
184 * @since 1.1.0
185 * @return void
186 */
187 private function woocommerce_field_state( $key, $args, $states ) {
188 ?>
189 <p id="<?php echo $key; ?>_field">
190 <span class="woocommerce-input-wrapper">
191 <?php
192 if ( ! is_array( $states ) || empty( $states ) ) {
193 $state = filter_input( INPUT_COOKIE, 'sellkit-checkout-billing-state' );
194
195 if ( 'shipping_state' === $key ) {
196 $state = filter_input( INPUT_COOKIE, 'sellkit-checkout-shipping-state' );
197 }
198
199 if ( empty( $state ) ) {
200 $state = '';
201 }
202
203 echo sprintf(
204 /* translators: 1: placeholder 2: name 3: id 4: default value */
205 '<input type="text" placeholder="%1$s" name="%2$s" id="%3$s" value="%4$s">',
206 esc_attr( $args['label'] ),
207 esc_attr__( 'State', 'sellkit' ),
208 esc_attr( 'sellkit-' . $key ),
209 esc_attr( $state ),
210 );
211
212 return;
213 }
214
215 $field = '<select id="sellkit-' . $key . '" name="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['label'] ) . '">
216 <option value="">' . esc_html__( 'Select a state…', 'sellkit' ) . '</option>';
217
218 foreach ( $states as $state_key => $state_label ) {
219 $field .= '<option value="' . esc_attr( $state_key ) . '" >' . esc_html( $state_label ) . '</option>';
220 }
221
222 $field .= '</select>';
223
224 echo $field;
225 ?>
226 </span>
227 </p>
228 <?php
229 }
230 }
231