PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.7.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.7.0
2.7.0 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 All 43 releases
← All changes | includes/elementor/modules/checkout/classes/helper.php +138 -13 1.1.42.7.0 View file →
@@ -47,8 +47,9 @@
47 47 public function billing_fields() {
48 48 return [
49 49 'billing_first_name' => esc_html__( 'Billing First Name', 'sellkit' ),
50 50 'billing_last_name' => esc_html__( 'Billing Last Name', 'sellkit' ),
51 + 'billing_company' => esc_html__( 'Billing Company', 'sellkit' ),
51 52 'billing_address_1' => esc_html__( 'Billing Address 1', 'sellkit' ),
52 53 'billing_address_2' => esc_html__( 'Billing Address 2', 'sellkit' ),
53 54 'billing_city' => esc_html__( 'Billing City', 'sellkit' ),
54 55 'billing_postcode' => esc_html__( 'Billing Postal Code', 'sellkit' ),
@@ -54,8 +55,9 @@
54 55 'billing_postcode' => esc_html__( 'Billing Postal Code', 'sellkit' ),
55 56 'billing_country' => esc_html__( 'Billing Country', 'sellkit' ),
56 57 'billing_state' => esc_html__( 'Billing State', 'sellkit' ),
57 58 'billing_email' => esc_html__( 'Billing State', 'sellkit' ),
59 + 'billing_phone' => esc_html__( 'Billing Phone', 'sellkit' ),
58 60 ];
59 61 }
60 62
61 63 /**
@@ -88,9 +90,11 @@
88 90 public function get_user_defined_fields_slug( $user_defined_fields, $type ) {
89 91 $fields = [];
90 92
91 93 foreach ( $user_defined_fields as $field ) {
92 - $fields[] = $field[ $type ];
94 + if ( isset( $field[ $type ] ) ) {
95 + $fields[] = $field[ $type ];
96 + }
93 97 }
94 98
95 99 return $fields;
96 100 }
@@ -236,13 +240,26 @@
236 240 * @param array $shipping_fields custom shipping fields.
237 241 * @param array $billing_fields custom billing fields.
238 242 * @return void
239 243 * @since 1.1.0
244 + * @SuppressWarnings(PHPMD.CyclomaticComplexity)
240 245 */
241 246 public function validate_user_defined_fields( $shipping_fields, $billing_fields ) {
247 + $shipping_destination = get_option( 'woocommerce_ship_to_destination', true );
248 +
242 249 foreach ( $shipping_fields as $data ) {
243 - $final_name = $data['shipping_list_field'];
250 + // Escape all if cart does not need shipping information.
251 + if ( ! WC()->cart->needs_shipping() ) {
252 + continue;
253 + }
244 254
255 + // Escape all if shipping destination be billing only.
256 + if ( 'billing_only' === $shipping_destination ) {
257 + continue;
258 + }
259 +
260 + $final_name = isset( $data['shipping_list_field'] ) ? $data['shipping_list_field'] : '';
261 +
245 262 if ( 'custom_role' === $final_name ) {
246 263 $final_name = 'shipping_' . $data['_id'];
247 264
248 265 if ( ! empty( $data['shipping_custom_id'] ) ) {
@@ -257,9 +274,9 @@
257 274 // Field value.
258 275 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
259 276
260 277 // #1. Required validation.
261 - $is_required = ( 'yes' === $data['shipping_list_required'] ) ? true : false;
278 + $is_required = ( ! empty( $data['shipping_list_required'] ) && 'yes' === $data['shipping_list_required'] ) ? true : false;
262 279
263 280 if ( true === $is_required && ( ! array_key_exists( $final_name, $_POST ) || empty( $value ) ) ) { // phpcs:ignore
264 281 /* translators: %s field_name. */
265 282 wc_add_notice( sprintf( __( '%s is a required field.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
@@ -272,9 +289,9 @@
272 289 $this->postcode_validation( $data, $final_name, 'shipping', $label );
273 290 }
274 291
275 292 foreach ( $billing_fields as $data ) {
276 - $final_name = $data['billing_list_field'];
293 + $final_name = isset( $data['billing_list_field'] ) ? $data['billing_list_field'] : '';
277 294
278 295 if ( 'custom_role' !== $final_name ) {
279 296 continue;
280 297 }
@@ -292,11 +309,11 @@
292 309 // Field value.
293 310 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT );
294 311
295 312 // #1. Required validation.
296 - $is_required = ( 'yes' === $data['billing_list_required'] ) ? true : false;
313 + $is_required = ( ! empty( $data['billing_list_required'] ) && 'yes' === $data['billing_list_required'] ) ? true : false;
297 314
298 - if ( true === $is_required && empty( $final_name ) ) { // phpcs:ignore
315 + if ( true === $is_required && empty( $value ) ) { // phpcs:ignore
299 316 /* translators: %s field_name. */
300 317 wc_add_notice( sprintf( __( '%s is a required field.', 'sellkit' ), '<strong>' . $label . '</strong>' ), 'error' );
301 318 }
302 319
@@ -423,9 +440,9 @@
423 440 $item = $this->prepare_custom_fields_to_save( $field, 'shipping' );
424 441 $final_name = $item['key_name'];
425 442
426 443 // Field value.
427 - $value = filter_input( INPUT_POST, $final_name, FILTER_SANITIZE_STRING );
444 + $value = sellkit_htmlspecialchars( INPUT_POST, $final_name );
428 445 if ( 'multiselect' === $field['shipping_custom_type'] ) {
429 446 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
430 447 }
431 448
@@ -444,9 +461,9 @@
444 461 $item = $this->prepare_custom_fields_to_save( $field, 'billing' );
445 462 $final_name = $item['key_name'];
446 463
447 464 // Field value.
448 - $value = filter_input( INPUT_POST, $final_name, FILTER_SANITIZE_STRING );
465 + $value = sellkit_htmlspecialchars( INPUT_POST, $final_name );
449 466 if ( 'multiselect' === $field['billing_custom_type'] ) {
450 467 $value = filter_input( INPUT_POST, $final_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
451 468 }
452 469
@@ -477,8 +494,9 @@
477 494 $item = [
478 495 'show_in_thank_you' => ( 'yes' === $data[ $type . '_show_in_thankyou' ] ) ? 'yes' : 'no',
479 496 'show_in_email' => ( 'yes' === $data[ $type . '_show_in_order_mail' ] ) ? 'yes' : 'no',
480 497 'key_name' => $final_name,
498 + 'label' => $data[ $type . '_list_placeholder' ],
481 499 ];
482 500
483 501 return $item;
484 502 }
@@ -500,12 +518,16 @@
500 518 unset( $default_fields['billing']['billing_email'] );
501 519
502 520 // Make it optional.
503 521 foreach ( $widget_billing_fields as $data ) {
504 - $slug = $data['billing_list_field'];
522 + $slug = isset( $data['billing_list_field'] ) ? $data['billing_list_field'] : '';
505 523 $is_required = false;
506 524
507 - if ( 'yes' === $data['billing_list_required'] ) {
525 + if ( 'custom_role' === $slug ) {
526 + continue;
527 + }
528 +
529 + if ( ! empty( $data['billing_list_required'] ) && 'yes' === $data['billing_list_required'] ) {
508 530 $is_required = true;
509 531 }
510 532
511 533 $default_fields['billing'][ $slug ]['required'] = $is_required;
@@ -511,12 +533,16 @@
511 533 $default_fields['billing'][ $slug ]['required'] = $is_required;
512 534 }
513 535
514 536 foreach ( $widget_shipping_fields as $data ) {
515 - $slug = $data['shipping_list_field'];
537 + $slug = isset( $data['shipping_list_field'] ) ? $data['shipping_list_field'] : '';
516 538 $is_required = false;
517 539
518 - if ( 'yes' === $data['shipping_list_required'] ) {
540 + if ( 'custom_role' === $slug ) {
541 + continue;
542 + }
543 +
544 + if ( ! empty( $data['shipping_list_required'] ) && 'yes' === $data['shipping_list_required'] ) {
519 545 $is_required = true;
520 546 }
521 547
522 548 $default_fields['shipping'][ $slug ]['required'] = $is_required;
@@ -587,13 +613,49 @@
587 613 public function checkout_order_hidden_quantity( $input_html, $quantity ) {
588 614 echo sprintf(
589 615 /** Translators: %s: product quantity */
590 616 '<strong class="product-quantity"> <i class="fa fa-times" aria-hidden="true"></i>%s</strong>',
591 - esc_html( $quantity ),
617 + esc_html( $quantity )
592 618 );
593 619 }
594 620
595 621 /**
622 + * Calculate item discount.
623 + *
624 + * @param int $id product id.
625 + * @param string $type discount type.
626 + * @param int $value discount value.
627 + * @return int|boolean
628 + * @since 1.2.8
629 + */
630 + public static function calculate_discount( $id, $type, $value ) {
631 + if ( false === $type && false === $value ) {
632 + return false;
633 + }
634 +
635 + $product = wc_get_product( $id );
636 + $regular = $product->get_regular_price();
637 + $sale = $product->get_sale_price();
638 + $price = false;
639 +
640 + if ( strpos( $type, 'sale' ) !== false ) {
641 + $discount = ( 'fixed-sale' === $type ) ? floatval( $value ) : ( floatval( $sale ) * floatval( $value ) ) / 100;
642 + $discount = floatval( $sale ) - $discount;
643 +
644 + return ( $discount > 0 ) ? $discount : 0;
645 + }
646 +
647 + if ( strpos( $type, 'sale' ) === false ) {
648 + $discount = ( 'fixed' === $type ) ? floatval( $value ) : ( floatval( $regular ) * floatval( $value ) ) / 100;
649 + $discount = floatval( $regular ) - $discount;
650 +
651 + return ( $discount > 0 ) ? $discount : 0;
652 + }
653 +
654 + return $price;
655 + }
656 +
657 + /**
596 658 * Add extra js in editor mode.
597 659 *
598 660 * @since 1.1.0
599 661 * @return void
@@ -624,6 +686,69 @@
624 686 } );
625 687 } );
626 688 </script>
627 689 <?php
690 + }
691 +
692 + /**
693 + * Assigning checkout ajax default shipping fields after ajax is sent.
694 + *
695 + * @param array $post post request.
696 + * @param array $clear checkout form data.
697 + * @return array
698 + * @since 1.2.8
699 + */
700 + public function assigning_default_ajax_shipping_fields( $post, $clear ) {
701 + if ( array_key_exists( 'billing_state', $clear ) ) {
702 + $post['state'] = $clear['billing_state'];
703 + }
704 +
705 + if ( array_key_exists( 'shipping_country', $clear ) ) {
706 + $post['s_country'] = $clear['shipping_country'];
707 + }
708 +
709 + if ( array_key_exists( 'shipping_state', $clear ) ) {
710 + $post['s_state'] = $clear['shipping_state'];
711 + }
712 +
713 + if ( array_key_exists( 'shipping_postcode', $clear ) ) {
714 + $post['s_postcode'] = $clear['shipping_postcode'];
715 + }
716 +
717 + if ( array_key_exists( 'shipping_city', $clear ) ) {
718 + $post['s_city'] = $clear['shipping_city'];
719 + }
720 +
721 + if ( array_key_exists( 'shipping_address_1', $clear ) ) {
722 + $post['s_address'] = $clear['shipping_address_1'];
723 + }
724 +
725 + if ( array_key_exists( 'shipping_address_2', $clear ) ) {
726 + $post['s_address_2'] = $clear['shipping_address_2'];
727 + }
728 +
729 + return $post;
730 + }
731 +
732 + /**
733 + * Check if product is in cart.
734 + *
735 + * @param int $product_id product id.
736 + * @since 1.7.4
737 + */
738 + public function is_product_in_cart( $product_id ) {
739 + // Get the WooCommerce cart.
740 + $cart = WC()->cart;
741 +
742 + foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
743 + // Get the product ID for each cart item.
744 + $item_product_id = $cart_item['product_id'];
745 +
746 + // Check if the product ID matches the provided product ID.
747 + if ( $item_product_id === $product_id ) {
748 + return true;
749 + }
750 + }
751 +
752 + return false;
628 753 }
629 754 }