← All changes
|
includes/elementor/modules/checkout/classes/helper.php
+36
-3
1.6.8
→
2.7.0
View file →
| @@ -90,9 +90,11 @@ | ||
| 90 | 90 | public function get_user_defined_fields_slug( $user_defined_fields, $type ) { |
| 91 | 91 | $fields = []; |
| 92 | 92 | |
| 93 | 93 | foreach ( $user_defined_fields as $field ) { |
| 94 | - $fields[] = $field[ $type ]; | |
| 94 | + if ( isset( $field[ $type ] ) ) { | |
| 95 | + $fields[] = $field[ $type ]; | |
| 96 | + } | |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | return $fields; |
| 98 | 100 | } |
| @@ -241,8 +243,10 @@ | ||
| 241 | 243 | * @since 1.1.0 |
| 242 | 244 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 243 | 245 | */ |
| 244 | 246 | public function validate_user_defined_fields( $shipping_fields, $billing_fields ) { |
| 247 | + $shipping_destination = get_option( 'woocommerce_ship_to_destination', true ); | |
| 248 | + | |
| 245 | 249 | foreach ( $shipping_fields as $data ) { |
| 246 | 250 | // Escape all if cart does not need shipping information. |
| 247 | 251 | if ( ! WC()->cart->needs_shipping() ) { |
| 248 | 252 | continue; |
| @@ -247,8 +251,13 @@ | ||
| 247 | 251 | if ( ! WC()->cart->needs_shipping() ) { |
| 248 | 252 | continue; |
| 249 | 253 | } |
| 250 | 254 | |
| 255 | + // Escape all if shipping destination be billing only. | |
| 256 | + if ( 'billing_only' === $shipping_destination ) { | |
| 257 | + continue; | |
| 258 | + } | |
| 259 | + | |
| 251 | 260 | $final_name = isset( $data['shipping_list_field'] ) ? $data['shipping_list_field'] : ''; |
| 252 | 261 | |
| 253 | 262 | if ( 'custom_role' === $final_name ) { |
| 254 | 263 | $final_name = 'shipping_' . $data['_id']; |
| @@ -280,9 +289,9 @@ | ||
| 280 | 289 | $this->postcode_validation( $data, $final_name, 'shipping', $label ); |
| 281 | 290 | } |
| 282 | 291 | |
| 283 | 292 | foreach ( $billing_fields as $data ) { |
| 284 | - $final_name = $data['billing_list_field']; | |
| 293 | + $final_name = isset( $data['billing_list_field'] ) ? $data['billing_list_field'] : ''; | |
| 285 | 294 | |
| 286 | 295 | if ( 'custom_role' !== $final_name ) { |
| 287 | 296 | continue; |
| 288 | 297 | } |
| @@ -485,8 +494,9 @@ | ||
| 485 | 494 | $item = [ |
| 486 | 495 | 'show_in_thank_you' => ( 'yes' === $data[ $type . '_show_in_thankyou' ] ) ? 'yes' : 'no', |
| 487 | 496 | 'show_in_email' => ( 'yes' === $data[ $type . '_show_in_order_mail' ] ) ? 'yes' : 'no', |
| 488 | 497 | 'key_name' => $final_name, |
| 498 | + 'label' => $data[ $type . '_list_placeholder' ], | |
| 489 | 499 | ]; |
| 490 | 500 | |
| 491 | 501 | return $item; |
| 492 | 502 | } |
| @@ -508,9 +518,9 @@ | ||
| 508 | 518 | unset( $default_fields['billing']['billing_email'] ); |
| 509 | 519 | |
| 510 | 520 | // Make it optional. |
| 511 | 521 | foreach ( $widget_billing_fields as $data ) { |
| 512 | - $slug = $data['billing_list_field']; | |
| 522 | + $slug = isset( $data['billing_list_field'] ) ? $data['billing_list_field'] : ''; | |
| 513 | 523 | $is_required = false; |
| 514 | 524 | |
| 515 | 525 | if ( 'custom_role' === $slug ) { |
| 516 | 526 | continue; |
| @@ -716,6 +726,29 @@ | ||
| 716 | 726 | $post['s_address_2'] = $clear['shipping_address_2']; |
| 717 | 727 | } |
| 718 | 728 | |
| 719 | 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; | |
| 720 | 753 | } |
| 721 | 754 | } |