} else { $field['disabled'] = false; } } } } } return $field; } public function disable_by_product( $field ) { if ( empty( $field['disabled'] ) && ( ! empty( $field['hide_product'] ) || ! empty( $field['show_product'] ) ) ) { $cart_contents = WC()->cart->get_cart_contents(); if ( is_object( WC()->cart ) && count( $cart_contents ) ) { $hide_ids_array = (array) $field['hide_product']; $show_ids_array = (array) $field['show_product']; $more_product = empty( $field['more_product'] ); $product_ids = array_column( $cart_contents, 'product_id' ); // field without more // ------------------------------------------------------------------- if ( $more_product && count( $cart_contents ) < 2 ) { // hide field // ----------------------------------------------------------------- if ( count( $hide_ids_array ) ) { if ( array_intersect( $product_ids, $hide_ids_array ) ) { $field['disabled'] = true; } } // show field // ----------------------------------------------------------------- if ( count( $show_ids_array ) ) { if ( ! array_intersect( $product_ids, $show_ids_array ) ) { $field['disabled'] = true; } else { $field['disabled'] = false; } } } // field with more // ------------------------------------------------------------------- if ( ! $more_product ) { // hide field // ------------------------------------------------------------- if ( count( $hide_ids_array ) ) { if ( array_intersect( $product_ids, $hide_ids_array ) ) { $field['disabled'] = true; } } // show field // --------------------------------------------------------------- if ( count( $show_ids_array ) ) { if ( ! array_intersect( $product_ids, $show_ids_array ) ) { $field['disabled'] = true; } else { $field['disabled'] = false; } } } } } return $field; } }