← All changes
|
includes/elementor/modules/checkout/fields/select.php
+52
-19
1.5.7
→
2.7.0
View file →
| @@ -62,18 +62,18 @@ | ||
| 62 | 62 | * @return void |
| 63 | 63 | * @since 1.1.0 |
| 64 | 64 | */ |
| 65 | 65 | public function field( $field, $args, $key ) { |
| 66 | - echo '<i class="fa fa-angle-down sellkit-select-appearance"></i>'; | |
| 66 | + echo '<span class="sellkit-select-appearance"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><path d="M201.4 342.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 274.7 86.6 137.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"/></svg></span>'; | |
| 67 | 67 | |
| 68 | + $default_value = ''; | |
| 69 | + if ( array_key_exists( 'default', $args ) ) { | |
| 70 | + $default_value = $args['default']; | |
| 71 | + } | |
| 72 | + | |
| 68 | 73 | if ( 'shipping_country' === $key || 'billing_country' === $key ) { |
| 69 | - $default = ''; | |
| 70 | - if ( array_key_exists( 'default', $args ) ) { | |
| 71 | - $default = $args['default']; | |
| 72 | - } | |
| 74 | + $this->woocommerce_field_country( $key, $default_value ); | |
| 73 | 75 | |
| 74 | - $this->woocommerce_field_country( $key, $default ); | |
| 75 | - | |
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | if ( 'shipping_state' === $key || 'billing_state' === $key ) { |
| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $states = WC()->countries->get_states( $country_code ); |
| 91 | 91 | |
| 92 | - $this->woocommerce_field_state( $key, $args, $states ); | |
| 92 | + $this->woocommerce_field_state( $key, $args, $states, $default_value ); | |
| 93 | 93 | |
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | 96 | |
| @@ -96,9 +96,9 @@ | ||
| 96 | 96 | |
| 97 | 97 | $placeholder = $this->placeholder_required_value( $args ); |
| 98 | 98 | |
| 99 | 99 | ?> |
| 100 | - <p id="<?php echo $key; ?>_field"> | |
| 100 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 101 | 101 | <span class="woocommerce-input-wrapper"> |
| 102 | 102 | <select |
| 103 | 103 | name="<?php echo esc_attr( $key ); ?>" |
| 104 | 104 | id="<?php echo esc_attr( $key ); ?>" |
| @@ -106,11 +106,8 @@ | ||
| 106 | 106 | autocomplete="country" |
| 107 | 107 | data-placeholder="<?php echo esc_attr( $placeholder ); ?>" |
| 108 | 108 | data-label="<?php echo ( array_key_exists( 'label', $args ) ) ? esc_attr( $args['label'] ) : ''; ?>" |
| 109 | 109 | > |
| 110 | - <?php | |
| 111 | - $default_value = ( array_key_exists( 'default', $args ) ) ? $args['default'] : ''; | |
| 112 | - ?> | |
| 113 | 110 | <?php foreach ( $args['options'] as $value => $label ) : ?> |
| 114 | 111 | <?php |
| 115 | 112 | if ( $value === $default_value ) { |
| 116 | 113 | echo sprintf( |
| @@ -146,9 +143,9 @@ | ||
| 146 | 143 | * @return void |
| 147 | 144 | */ |
| 148 | 145 | private function woocommerce_field_country( $key, $default ) { |
| 149 | 146 | ?> |
| 150 | - <p id="<?php echo $key; ?>_field"> | |
| 147 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 151 | 148 | <span class="woocommerce-input-wrapper"> |
| 152 | 149 | <?php |
| 153 | 150 | $countries = WC()->countries->get_shipping_countries(); |
| 154 | 151 | |
| @@ -170,9 +167,27 @@ | ||
| 170 | 167 | |
| 171 | 168 | $field .= '</select>'; |
| 172 | 169 | $field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' . esc_attr__( 'Update country', 'sellkit' ) . '" /></noscript>'; |
| 173 | 170 | |
| 174 | - echo $field; | |
| 171 | + $allowed_html = [ | |
| 172 | + 'select' => [ | |
| 173 | + 'name' => true, | |
| 174 | + 'id' => true, | |
| 175 | + 'class' => true, | |
| 176 | + ], | |
| 177 | + 'option' => [ | |
| 178 | + 'value' => true, | |
| 179 | + 'selected' => true, | |
| 180 | + ], | |
| 181 | + 'noscript' => [], | |
| 182 | + 'input' => [ | |
| 183 | + 'type' => true, | |
| 184 | + 'name' => true, | |
| 185 | + 'value' => true, | |
| 186 | + ], | |
| 187 | + ]; | |
| 188 | + | |
| 189 | + echo wp_kses( $field, $allowed_html ); | |
| 175 | 190 | ?> |
| 176 | 191 | </span> |
| 177 | 192 | </p> |
| 178 | 193 | <?php |
| @@ -183,16 +198,17 @@ | ||
| 183 | 198 | * |
| 184 | 199 | * @param string $key field key. |
| 185 | 200 | * @param array $args field options. |
| 186 | 201 | * @param array $states country states. |
| 202 | + * @param string $default_value field default value. | |
| 187 | 203 | * @since 1.1.0 |
| 188 | 204 | * @return void |
| 189 | 205 | */ |
| 190 | - private function woocommerce_field_state( $key, $args, $states ) { | |
| 206 | + private function woocommerce_field_state( $key, $args, $states, $default_value ) { | |
| 191 | 207 | $placeholder = $this->placeholder_required_value( $args ); |
| 192 | 208 | |
| 193 | 209 | ?> |
| 194 | - <p id="<?php echo $key; ?>_field"> | |
| 210 | + <p id="<?php echo esc_attr( $key ); ?>_field"> | |
| 195 | 211 | <span class="woocommerce-input-wrapper"> |
| 196 | 212 | <?php |
| 197 | 213 | if ( ! is_array( $states ) || empty( $states ) ) { |
| 198 | 214 | $state = filter_input( INPUT_COOKIE, 'sellkit-checkout-billing-state' ); |
| @@ -216,18 +232,35 @@ | ||
| 216 | 232 | |
| 217 | 233 | return; |
| 218 | 234 | } |
| 219 | 235 | |
| 220 | - $field = '<select id="sellkit-' . $key . '" name="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['label'] ) . '"> | |
| 236 | + $field = '<select id="sellkit-' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['label'] ) . '"> | |
| 221 | 237 | <option value="">' . esc_html__( 'Select a state…', 'sellkit' ) . '</option>'; |
| 222 | 238 | |
| 223 | 239 | foreach ( $states as $state_key => $state_label ) { |
| 224 | - $field .= '<option value="' . esc_attr( $state_key ) . '" >' . esc_html( $state_label ) . '</option>'; | |
| 240 | + $selected = ''; | |
| 241 | + | |
| 242 | + if ( $default_value === $state_key ) { | |
| 243 | + $selected = 'selected'; | |
| 244 | + } | |
| 245 | + $field .= '<option ' . $selected . ' value="' . esc_attr( $state_key ) . '" >' . esc_html( $state_label ) . '</option>'; | |
| 225 | 246 | } |
| 226 | 247 | |
| 227 | 248 | $field .= '</select>'; |
| 228 | 249 | |
| 229 | - echo $field; | |
| 250 | + $allowed_html = [ | |
| 251 | + 'select' => [ | |
| 252 | + 'id' => true, | |
| 253 | + 'name' => true, | |
| 254 | + 'placeholder' => true, | |
| 255 | + ], | |
| 256 | + 'option' => [ | |
| 257 | + 'value' => true, | |
| 258 | + 'selected' => true, | |
| 259 | + ], | |
| 260 | + ]; | |
| 261 | + | |
| 262 | + echo wp_kses( $field, $allowed_html ); | |
| 230 | 263 | ?> |
| 231 | 264 | </span> |
| 232 | 265 | </p> |
| 233 | 266 | <?php |