PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.3.1
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.3.1
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 / classes / helper.php

helper.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.3.1, at includes/elementor/modules/checkout/classes/helper.php

706 lines 22.4 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\Classes;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use Elementor\Plugin as Elementor;
8
9 /**
10 * Helper class.
11 *
12 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
13 * @SuppressWarnings(PHPMD.NPathComplexity)
14 * @since 1.1.0
15 */
16 class Helper {
17
18 /**
19 * Instance of this class.
20 *
21 * @since NEXT
22 * @access public
23 * @var Checkout
24 */
25 public static $instance;
26
27 /**
28 * Provides access to a single instance of a module using the singleton pattern.
29 *
30 * @since NEXT
31 * @return object
32 */
33 public static function instance() {
34 if ( null === self::$instance ) {
35 self::$instance = new self();
36 }
37
38 return self::$instance;
39 }
40
41 /**
42 * Default sellkit checkout widget billing fields.
43 *
44 * @return array
45 * @since 1.1.0
46 */
47 public function billing_fields() {
48 return [
49 'billing_first_name' => esc_html__( 'Billing First Name', 'sellkit' ),
50 'billing_last_name' => esc_html__( 'Billing Last Name', 'sellkit' ),
51 'billing_address_1' => esc_html__( 'Billing Address 1', 'sellkit' ),
52 'billing_address_2' => esc_html__( 'Billing Address 2', 'sellkit' ),
53 'billing_city' => esc_html__( 'Billing City', 'sellkit' ),
54 'billing_postcode' => esc_html__( 'Billing Postal Code', 'sellkit' ),
55 'billing_country' => esc_html__( 'Billing Country', 'sellkit' ),
56 'billing_state' => esc_html__( 'Billing State', 'sellkit' ),
57 'billing_email' => esc_html__( 'Billing State', 'sellkit' ),
58 ];
59 }
60
61 /**
62 * Default sellkit checkout widget shipping fields.
63 *
64 * @return array
65 * @since 1.1.0
66 */
67 public function shipping_fields() {
68 return [
69 'shipping_first_name' => esc_html__( 'shipping First Name', 'sellkit' ),
70 'shipping_last_name' => esc_html__( 'shipping Last Name', 'sellkit' ),
71 'shipping_address_1' => esc_html__( 'shipping Address 1', 'sellkit' ),
72 'shipping_address_2' => esc_html__( 'shipping Address 2', 'sellkit' ),
73 'shipping_city' => esc_html__( 'shipping City', 'sellkit' ),
74 'shipping_postcode' => esc_html__( 'shipping Postal Code', 'sellkit' ),
75 'shipping_country' => esc_html__( 'shipping Country', 'sellkit' ),
76 'shipping_state' => esc_html__( 'shipping State', 'sellkit' ),
77 ];
78 }
79
80 /**
81 * Gets user defined fields and return array of slug.
82 *
83 * @param array $user_defined_fields widget fields.
84 * @param string $type billing/shipping field.
85 * @return array
86 * @since 1.1.0
87 */
88 public function get_user_defined_fields_slug( $user_defined_fields, $type ) {
89 $fields = [];
90
91 foreach ( $user_defined_fields as $field ) {
92 $fields[] = $field[ $type ];
93 }
94
95 return $fields;
96 }
97
98 /**
99 * Assign user defined values to each field.
100 *
101 * @param array $default_fields : default woocommerce fields.
102 * @param array $widget_fields : fields get added by user from widget option.
103 * @param string $type : shipping / billing.
104 * @param array $settings : whole widget settings.
105 * @return array
106 * @since 1.1.0
107 * @SuppressWarnings(PHPMD.NPathComplexity)
108 */
109 public function assign_settings_per_field( $default_fields, $widget_fields, $type, $settings ) {
110 // Assign user properties.
111 foreach ( $widget_fields as $key => $field ) {
112 $field_slug = $field[ $type . '_list_field' ];
113 $is_custom = false;
114
115 // IF field is a custom field we replace key with id. So it will be unique.
116 // !important: user has to define id for each field using custom id field.
117 if ( 'custom_role' === $field_slug ) {
118 // Create billing_bla_bla & shipping_bla_bla for custom field.
119 $field_slug = $type . '_' . $field['_id'];
120
121 if ( ! empty( $field[ $type . '_custom_id' ] ) ) {
122 $field_slug = $type . '_' . $field[ $type . '_custom_id' ];
123 }
124
125 $is_custom = true;
126 }
127
128 $default_fields[ $field_slug ]['label'] = $field[ $type . '_list_placeholder' ];
129 $default_fields[ $field_slug ]['class'] = explode( ' ', $field[ $type . '_list_class' ] ); // phpcs:ignore
130 $default_fields[ $field_slug ]['class'][] = $field[ $type . '_width' ];
131 $default_fields[ $field_slug ]['class'][] = 'sellkit-widget-checkout-fields';
132 $default_fields[ $field_slug ]['class'][] = 'sellkit-checkout-fields-validation-' . $field[ $type . '_list_validation' ];
133 $default_fields[ $field_slug ]['required'] = ( 'yes' === $field[ $type . '_list_required' ] ) ? true : false;
134 $default_fields[ $field_slug ]['clear'] = ( 'yes' === $field[ $type . '_list_clear' ] ) ? true : false;
135 $default_fields[ $field_slug ]['priority'] = ( $key + 1 ) * 10;
136 // Widget defined fields are local. third party plugins's fields are not.
137 $default_fields[ $field_slug ]['local'] = true;
138
139 // Append postal code autocomplete class.
140 if (
141 array_key_exists( 'state_lookup_by_postcode', $settings )
142 && 'yes' === $settings['state_lookup_by_postcode']
143 && ( 'billing_postcode' === $field_slug || 'shipping_postcode' === $field_slug )
144 ) {
145 $default_fields[ $field_slug ]['class'][] = 'post_code_autocomplete';
146 }
147
148 // IF not custom field, go next.
149 if ( false === $is_custom ) {
150 continue;
151 }
152
153 $default_fields = $this->custom_field_setup( $field, $type, $field_slug, $default_fields );
154 }
155
156 foreach ( $default_fields as $key => $details ) {
157 if ( ! array_key_exists( 'local', $details ) || false === $details['local'] ) {
158 $default_fields[ $key ]['priority'] = 500;
159 }
160 }
161
162 return $default_fields;
163 }
164
165 /**
166 * Setup custom field options and assign required things to custom fields.
167 * also helps to reduce assign_settings_per_field method complexity.
168 *
169 * @param array $field html string of checkout fields.
170 * @param string $type type of checkout fields.
171 * @param string $field_slug unique sluf per field.
172 * @param array $default_fields default checkout fields.
173 * @return array
174 * @since 1.1.0
175 */
176 private function custom_field_setup( $field, $type, $field_slug, $default_fields ) {
177 $tag = $field[ $type . '_custom_type' ];
178
179 // Set default options.
180 $default_fields[ $field_slug ]['class'][] = ( $field[ $type . '_width' ] ) ? $field[ $type . '_width' ] : 'w-100';
181 $default_fields[ $field_slug ]['type'] = ( $field[ $type . '_custom_type' ] ) ? $field[ $type . '_custom_type' ] : 'text';
182 $default_fields[ $field_slug ]['default'] = $field[ $type . '_custom_value' ];
183
184 // Convert select to multiselect.
185 if ( 'multiselect' === $tag ) {
186 $default_fields[ $field_slug ]['type'] = 'multiselect';
187 }
188
189 // Assign one extra class to style radio group wrapper.
190 if ( 'radio' === $tag ) {
191 $default_fields[ $field_slug ]['type'] = 'radio';
192 $default_fields[ $field_slug ]['class'][] = 'radio-group-wrapper';
193 $default_fields[ $field_slug ]['mode'] = $field[ $type . '_radio_field_mode' ];
194 }
195
196 // Check if checkbox must be checked on default.
197 if ( 'checkbox' === $tag ) {
198 $default_fields[ $field_slug ]['checked'] = $field[ $type . '_checkbox_custom_value' ];
199 }
200
201 // Assign options.
202 $tags = [ 'select', 'multiselect', 'radio' ];
203 if ( in_array( $tag, $tags, true ) ) {
204 $options = $this->convert_value_to_array( $field[ $type . '_custom_options' ] );
205
206 $default_fields[ $field_slug ]['options'] = $options;
207 }
208
209 return $default_fields;
210 }
211
212 /**
213 * Gets widget options string and convert it to array to be used for select / radio and etc.
214 *
215 * @param string $value string of options.
216 * @return array
217 * @since 1.1.0
218 */
219 private function convert_value_to_array( $value ) {
220 $array = [];
221 $values = preg_split( '/\r\n|\r|\n/', $value );
222
223 foreach ( $values as $option ) {
224 $split = explode( ':', $option );
225 $array[ $split[0] ] = $split[1];
226 }
227
228 return $array;
229 }
230
231 /**
232 * Is used to validate user defined custom fields after pressing place order button at checkout page.
233 * Validate both custom shipping and billing fields at once if exists.
234 *
235 * @uses sellkit_Core\Raven\Modules\Checkout\Classes\Global_Hooks::validate_user_defined_fields
236 * @param array $shipping_fields custom shipping fields.
237 * @param array $billing_fields custom billing fields.
238 * @return void
239 * @since 1.1.0
240 */
241 public function validate_user_defined_fields( $shipping_fields, $billing_fields ) {
242 foreach ( $shipping_fields as $data ) {
243 $final_name = $data['shipping_list_field'];
244
245 if ( 'custom_role' === $final_name ) {
246 $final_name = 'shipping_' . $data['_id'];
247
248 if ( ! empty( $data['shipping_custom_id'] ) ) {
249 $id = $data['shipping_custom_id'];
250 $final_name = "shipping_$id";
251 }
252 }
253
254 // Get $name variable from label or placeholder and/or id to be used in validate error.
255 $label = $this->create_name_for_errors( $data, __( 'Shipping', 'sellkit' ), 'shipping', $final_name );
256
257 // Field value.
258 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
259
260 // #1. Required validation.
261 $is_required = ( ! empty( $data['shipping_list_required'] ) && 'yes' === $data['shipping_list_required'] ) ? true : false;
262
263 if ( true === $is_required && ( ! array_key_exists( $final_name, $_POST ) || empty( $value ) ) ) { // phpcs:ignore
264 /* translators: %s field_name. */
265 wc_add_notice( sprintf( __( '%s is a required field.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
266 }
267
268 // #2. Phone validation.
269 $this->phone_validation( $data, $final_name, 'shipping', $label );
270
271 // #3. Postcode validation.
272 $this->postcode_validation( $data, $final_name, 'shipping', $label );
273 }
274
275 foreach ( $billing_fields as $data ) {
276 $final_name = $data['billing_list_field'];
277
278 if ( 'custom_role' !== $final_name ) {
279 continue;
280 }
281
282 $final_name = 'billing_' . $data['_id'];
283
284 if ( ! empty( $data['billing_custom_id'] ) ) {
285 $id = $data['billing_custom_id'];
286 $final_name = "billing_$id";
287 }
288
289 // Get $name variable from label or placeholder and/or id to be used in validate error.
290 $label = $this->create_name_for_errors( $data, __( 'Billing', 'sellkit' ), 'billing', $final_name );
291
292 // Field value.
293 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
294
295 // #1. Required validation.
296 $is_required = ( 'yes' === $data['billing_list_required'] ) ? true : false;
297
298 if ( true === $is_required && empty( $final_name ) ) { // phpcs:ignore
299 /* translators: %s field_name. */
300 wc_add_notice( sprintf( __( '%s is a required field.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
301 }
302
303 // #2. phone validation.
304 $this->phone_validation( $data, $final_name, 'billing', $label );
305
306 // #3. Postcode validation.
307 $this->postcode_validation( $data, $final_name, 'billing', $label );
308 }
309
310 // Validate main checkout email.
311 $email = filter_input( INPUT_POST, 'billing_email', FILTER_SANITIZE_EMAIL );
312 $valid = filter_var( $email, FILTER_VALIDATE_EMAIL );
313
314 if ( ! $email ) {
315 /* translators: %s field_name. */
316 wc_add_notice( sprintf( __( '%s is a required field.', 'sellkit' ), '<strong>' . __( 'Email address', 'sellkit' ) . '</strong>' ), 'error' );
317 return;
318 }
319
320 if ( ! $valid ) {
321 /* translators: %s field_name. */
322 wc_add_notice( sprintf( __( '%s is not a valid email.', 'sellkit' ), '<strong>' . __( 'Email address', 'sellkit' ) . '</strong>' ), 'error' );
323 }
324 }
325
326 /**
327 * Create name for each field to be used in errors text.
328 *
329 * @param array $data field data.
330 * @param string $display_type shipping / billing with text-domain.
331 * @param string $type shipping / billing.
332 * @param string $final_name field key.
333 * @return string
334 * @since 1.1.0
335 */
336 private function create_name_for_errors( $data, $display_type, $type, $final_name ) {
337 $name = $data[ $type . '_list_placeholder' ];
338
339 if ( empty( $data[ $type . '_list_placeholder' ] ) ) {
340 $name = $data[ $type . '_list_label' ];
341 }
342
343 $label = $display_type . ' ' . $name;
344
345 if ( empty( $name ) ) {
346 $label = $final_name;
347 }
348
349 return $label;
350 }
351
352 /**
353 * Validate phone number using woocommerce way.
354 *
355 * @see woocommerce/includes/class-wc-validation.php
356 * @param array $data widget field data.
357 * @param string $final_name key of field in checkout form.
358 * @param string $type shipping/billing.
359 * @param string $label field label for error.
360 * @return boolean
361 * @since 1.1.0
362 */
363 private function phone_validation( $data, $final_name, $type, $label ) {
364 if ( ! array_key_exists( $type . '_list_validation', $data ) || 'phone' !== $data[ $type . '_list_validation' ] ) {
365 return true;
366 }
367
368 $phone = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
369 $valid = \WC_Validation::is_phone( $phone );
370
371 if ( ! $valid ) {
372 /* translators: %s field_name. */
373 wc_add_notice( sprintf( __( '%s is not a valid phone.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
374 }
375 }
376
377 /**
378 * Validate postcode using woocommerce way.
379 *
380 * @param array $data field data.
381 * @param string $final_name field key in checkout form.
382 * @param string $type shipping / billing.
383 * @param string $label field label to be used in error text.
384 * @return void
385 * @since 1.1.0
386 */
387 private function postcode_validation( $data, $final_name, $type, $label ) {
388 if ( ! array_key_exists( $type . '_list_validation', $data ) || 'postcode' !== $data[ $type . '_list_validation' ] ) {
389 return;
390 }
391
392 $postcode = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
393 $country = filter_input( INPUT_POST, $type . '_country' );
394 $postcode = wc_format_postcode( $postcode, $country );
395 $valid = \WC_Validation::is_postcode( $postcode, $country );
396
397 if ( ! $valid ) {
398 /* translators: %s field_name. */
399 wc_add_notice( sprintf( __( '%s is not a valid postcode.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
400 }
401 }
402
403 /**
404 * Is used to save user defined custom fields in database for the current order id.
405 * save both billing and shipping custom fields at once if exists.
406 *
407 * @uses sellkit_Core\Raven\Modules\Checkout\Classes\Global_Hooks::save_user_defined_fields
408 * @param array $shipping_fields custom shipping fields.
409 * @param array $billing_fields custom billing fields.
410 * @param int $order_id order id.
411 * @return void
412 * @since 1.1.0
413 */
414 public function save_user_defined_fields( $shipping_fields, $billing_fields, $order_id ) {
415 // We store saved fields in this array and save keys as a meta for this order, to use it later.
416 $saved_fields = [];
417
418 foreach ( $shipping_fields as $field ) {
419 if ( empty( $field['shipping_custom_id'] ) ) {
420 continue;
421 }
422
423 $item = $this->prepare_custom_fields_to_save( $field, 'shipping' );
424 $final_name = $item['key_name'];
425
426 // Field value.
427 $value = sellkit_htmlspecialchars( INPUT_POST, $final_name );
428 if ( 'multiselect' === $field['shipping_custom_type'] ) {
429 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
430 }
431
432 // Some user defined field might be not required ( & empty ). so again we check if field is has value save it.
433 if ( ! empty( $value ) ) { // phpcs:ignore
434 update_post_meta( $order_id, $final_name, sanitize_text_field( $value ) ); // phpcs:ignore
435 array_push( $saved_fields, $item );
436 }
437 }
438
439 foreach ( $billing_fields as $field ) {
440 if ( empty( $field['billing_custom_id'] ) ) {
441 continue;
442 }
443
444 $item = $this->prepare_custom_fields_to_save( $field, 'billing' );
445 $final_name = $item['key_name'];
446
447 // Field value.
448 $value = sellkit_htmlspecialchars( INPUT_POST, $final_name );
449 if ( 'multiselect' === $field['billing_custom_type'] ) {
450 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
451 }
452
453 // Some user defined field might be not required ( & empty ). so again we check if field has value save it.
454 if ( ! empty( $value ) ) { // phpcs:ignore
455 update_post_meta( $order_id, $final_name, sanitize_text_field( $value ) ); // phpcs:ignore
456 array_push( $saved_fields, $item );
457 }
458 }
459
460 // Save id of those custom fields that are validate and has value as an meta for order to be used later.
461 if ( count( $saved_fields ) > 0 ) {
462 update_post_meta( $order_id, 'sellkit_checkout_widget_custom_field_of_order', $saved_fields );
463 }
464 }
465
466 /**
467 * The way to save custom fields names as array for order as meta to be used later.
468 *
469 * @param array $data sent data from checkout.
470 * @param string $type shippin/billing.
471 * @return array
472 * @since 1.1.0
473 */
474 private function prepare_custom_fields_to_save( $data, $type ) {
475 $id = $data[ $type . '_custom_id' ];
476 $final_name = $type . '_' . $id;
477 $item = [
478 'show_in_thank_you' => ( 'yes' === $data[ $type . '_show_in_thankyou' ] ) ? 'yes' : 'no',
479 'show_in_email' => ( 'yes' === $data[ $type . '_show_in_order_mail' ] ) ? 'yes' : 'no',
480 'key_name' => $final_name,
481 ];
482
483 return $item;
484 }
485
486 /**
487 * Convert required fields to optional based on widget options.
488 * will be called after clicking place order button.
489 *
490 * @uses sellkit_Core\Raven\Modules\Checkout\Classes\Global_Hooks::validate_user_defined_fields
491 * @param array $widget_shipping_fields user defined fields in widget.
492 * @param array $widget_billing_fields user defined fields in widget.
493 * @return void
494 * @since 1.1.0
495 */
496 public function make_sure_to_convert_required_field_to_optional( $widget_shipping_fields, $widget_billing_fields ) {
497 add_filter( 'woocommerce_checkout_fields', function( $default_fields ) use ( $widget_shipping_fields, $widget_billing_fields ) {
498 // Make phone field optional at beginning.
499 $default_fields['billing']['billing_phone']['required'] = false;
500 unset( $default_fields['billing']['billing_email'] );
501
502 // Make it optional.
503 foreach ( $widget_billing_fields as $data ) {
504 $slug = $data['billing_list_field'];
505 $is_required = false;
506
507 if ( ! empty( $data['billing_list_required'] ) && 'yes' === $data['billing_list_required'] ) {
508 $is_required = true;
509 }
510
511 $default_fields['billing'][ $slug ]['required'] = $is_required;
512 }
513
514 foreach ( $widget_shipping_fields as $data ) {
515 $slug = $data['shipping_list_field'];
516 $is_required = false;
517
518 if ( ! empty( $data['shipping_list_required'] ) && 'yes' === $data['shipping_list_required'] ) {
519 $is_required = true;
520 }
521
522 $default_fields['shipping'][ $slug ]['required'] = $is_required;
523 }
524
525 return $default_fields;
526 } );
527 }
528
529 /**
530 * Retrieve required widget settings of current checkout widget.
531 *
532 * @param int $post_id page id.
533 * @param string $form_id form id.
534 * @return array
535 * @since 1.1.0
536 */
537 public function retrieve_checkout_widget_settings( $post_id, $form_id ) {
538 $form_meta = Elementor::$instance->documents->get( $post_id )->get_elements_data();
539 $form = self::find_element_recursive( $form_meta, $form_id );
540
541 if ( ! is_array( $form ) || ! array_key_exists( 'settings', $form ) ) {
542 return [];
543 }
544
545 $settings = $form['settings'];
546
547 return $settings;
548 }
549
550 /**
551 * Find elementor element.
552 * Code block copied from sellkit-core directly.
553 *
554 * @param array $elements elements of elementor.
555 * @param string $form_id elementor form id.
556 * @return array
557 * @since 1.1.0
558 */
559 public static function find_element_recursive( $elements, $form_id ) {
560 foreach ( $elements as $element ) {
561 if ( $form_id === $element['id'] ) {
562 return $element;
563 }
564
565 if ( ! empty( $element['elements'] ) ) {
566 $element = self::find_element_recursive( $element['elements'], $form_id );
567
568 if ( $element ) {
569 return $element;
570 }
571 }
572 }
573
574 return false;
575 }
576
577 /**
578 * Hide checkout order product quantity input and show raw quantity.
579 *
580 * @param string $input_html default quantity input.
581 * @param int $quantity product quantity in cart.
582 * @since 1.1.0
583 * @return void
584 *
585 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
586 */
587 public function checkout_order_hidden_quantity( $input_html, $quantity ) {
588 echo sprintf(
589 /** Translators: %s: product quantity */
590 '<strong class="product-quantity"> <i class="fa fa-times" aria-hidden="true"></i>%s</strong>',
591 esc_html( $quantity )
592 );
593 }
594
595 /**
596 * Calculate item discount.
597 *
598 * @param int $id product id.
599 * @param string $type discount type.
600 * @param int $value discount value.
601 * @return int|boolean
602 * @since 1.2.8
603 */
604 public static function calculate_discount( $id, $type, $value ) {
605 if ( false === $type && false === $value ) {
606 return false;
607 }
608
609 $product = wc_get_product( $id );
610 $regular = $product->get_regular_price();
611 $sale = $product->get_sale_price();
612 $price = false;
613
614 if ( strpos( $type, 'sale' ) !== false ) {
615 $discount = ( 'fixed-sale' === $type ) ? floatval( $value ) : ( floatval( $sale ) * floatval( $value ) ) / 100;
616 $discount = floatval( $sale ) - $discount;
617
618 return ( $discount > 0 ) ? $discount : 0;
619 }
620
621 if ( strpos( $type, 'sale' ) === false ) {
622 $discount = ( 'fixed' === $type ) ? floatval( $value ) : ( floatval( $regular ) * floatval( $value ) ) / 100;
623 $discount = floatval( $regular ) - $discount;
624
625 return ( $discount > 0 ) ? $discount : 0;
626 }
627
628 return $price;
629 }
630
631 /**
632 * Add extra js in editor mode.
633 *
634 * @since 1.1.0
635 * @return void
636 */
637 public function editor_mode_extra_js() {
638 ?>
639 <script>
640 jQuery( document ).on( 'mousemove', function() {
641 $( '.sellkit-coupon-toggle' ).off( 'click' ).on( 'click', function() {
642 let direction = 'row';
643 const status = $( '.sellkit-custom-coupon-form' ).css( 'display' );
644 let displayValue = '';
645
646 if ( $( window ).width() < 600 ) {
647 direction = 'column';
648 }
649
650 if ( 'none' === status ) {
651 displayValue = 'inline-flex';
652 } else {
653 displayValue = 'none';
654 }
655
656 $( '.sellkit-custom-coupon-form' ).css( {
657 display: displayValue,
658 flexDirection: direction,
659 } );
660 } );
661 } );
662 </script>
663 <?php
664 }
665
666 /**
667 * Assigning checkout ajax default shipping fields after ajax is sent.
668 *
669 * @param array $post post request.
670 * @param array $clear checkout form data.
671 * @return array
672 * @since 1.2.8
673 */
674 public function assigning_default_ajax_shipping_fields( $post, $clear ) {
675 if ( array_key_exists( 'billing_state', $clear ) ) {
676 $post['state'] = $clear['billing_state'];
677 }
678
679 if ( array_key_exists( 'shipping_country', $clear ) ) {
680 $post['s_country'] = $clear['shipping_country'];
681 }
682
683 if ( array_key_exists( 'shipping_state', $clear ) ) {
684 $post['s_state'] = $clear['shipping_state'];
685 }
686
687 if ( array_key_exists( 'shipping_postcode', $clear ) ) {
688 $post['s_postcode'] = $clear['shipping_postcode'];
689 }
690
691 if ( array_key_exists( 'shipping_city', $clear ) ) {
692 $post['s_city'] = $clear['shipping_city'];
693 }
694
695 if ( array_key_exists( 'shipping_address_1', $clear ) ) {
696 $post['s_address'] = $clear['shipping_address_1'];
697 }
698
699 if ( array_key_exists( 'shipping_address_2', $clear ) ) {
700 $post['s_address_2'] = $clear['shipping_address_2'];
701 }
702
703 return $post;
704 }
705 }
706