← All changes
|
includes/elementor/modules/checkout/classes/helper.php
+56
-7
1.2.9
→
2.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'] ) ) { |
| @@ -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 | |
| @@ -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,11 +518,15 @@ | ||
| 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 | |
| 525 | + if ( 'custom_role' === $slug ) { | |
| 526 | + continue; | |
| 527 | + } | |
| 528 | + | |
| 507 | 529 | if ( ! empty( $data['billing_list_required'] ) && 'yes' === $data['billing_list_required'] ) { |
| 508 | 530 | $is_required = true; |
| 509 | 531 | } |
| 510 | 532 | |
| @@ -511,11 +533,15 @@ | ||
| 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 | |
| 540 | + if ( 'custom_role' === $slug ) { | |
| 541 | + continue; | |
| 542 | + } | |
| 543 | + | |
| 518 | 544 | if ( ! empty( $data['shipping_list_required'] ) && 'yes' === $data['shipping_list_required'] ) { |
| 519 | 545 | $is_required = true; |
| 520 | 546 | } |
| 521 | 547 | |
| @@ -700,6 +726,29 @@ | ||
| 700 | 726 | $post['s_address_2'] = $clear['shipping_address_2']; |
| 701 | 727 | } |
| 702 | 728 | |
| 703 | 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; | |
| 704 | 753 | } |
| 705 | 754 | } |