'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'language' => get_locale(), 'suppress_filters' => false, ); $is_in_colors_bool = false; $is_in_devices_bool = false; $is_in_types_bool = false; if (isset($_GET['s']) && $_GET['s'] != '') { $search_string = $_GET['s']; $colors = implode(',', array_keys(GetColors())); $devices = implode(',', array_keys(GetDevices())); $case_types = implode(',', array_keys(GetCases())); $is_in_colors = stripos($colors, $search_string); $is_in_devices = stripos($devices, $search_string); $is_in_types = stripos($case_types, $search_string); if ($is_in_colors !== false) { $is_in_colors_bool = true; } if ($is_in_devices !== false) { $is_in_devices_bool = true; } if ($is_in_types !== false) { $is_in_types_bool = true; } if (($is_in_colors != true) && ($is_in_devices != true) && ($is_in_types_bool != true)) { $args['s'] = $search_string; } } $query = new WP_Query($args); $products_raw = $query->posts; $base_colors = GetColors(); if ($products_raw) { foreach( $products_raw as $key=>$item ) { $meta = get_post_meta( $item->ID ); $url = get_post_permalink( $item->ID ); $english_product = OriginalPostWpml( $item->ID ); $variations_full = GetProductVariations( $english_product ); $variations = array_slice( $variations_full, 0, 10000 ); $prices = array(); foreach( $variations_full as $offer ) { $options[ $offer['params']['device'] ] = $offer['params']['device']; $prices[] = $offer['price']; } $cat = get_the_terms( $item->ID, 'product_cat' )[0]; $products[ $key ] = array( "ID" => $item->ID, "category" => $cat->name, "post_title" => $item->post_title, "post_content" => $item->post_content, "img" => get_the_post_thumbnail_url( $item->ID ), "url" => $url, "min_price" => min( $prices ), "variations" => $variations, ); } } else { $message = __('Nothing found.', 'blackrock'); } if( $_GET['s'] && count($products) >= 0 ) { $device = $_GET['device']; $device_info = GetDeviceByTitle( $device ); $sections = array(); foreach( $products as $item ) { if( $item['variations'] ) { foreach( $item['variations'] as $offer ) { if( $offer['params']['case-type'] && $offer['params']['device'] ) { $params_raw = $offer['params']; unset( $params_raw['color-material'] ); $params = http_build_query( $params_raw ); $url = $item['url'].'?'.$params; $section_key = $offer['params']['device'].' '.$offer['params']['case-type']; $sections[ $section_key ][ $item['post_title'] ][] = array( //"title" => $item['post_title'].' '.$offer['params']['color-material'], "title" => $item['post_title'], "url" => $url, "params" => $offer['params'], "img" => $item['img'], "sku" => $offer['sku'], "price" => $item['min_price'], "stock" => $offer['stock'], ); $section_key_new = $section_key . ' ' . $item['post_title']; if( $_GET['device'] ) { if( strtolower($offer['params']['device']) != strtolower($_GET['device']) ) { unset( $sections[ $section_key ] ); } } $counter = 0; if (str_word_count($_GET['s']) > 1) { $search_string_array = explode(' ', $_GET['s']); if (!contains_all($section_key_new, $search_string_array)) { unset( $sections[ $section_key ] ); } } else { if ($is_in_devices_bool) { if (stripos($offer['params']['device'], $_GET['s']) === false) { unset( $sections[ $section_key ] ); } } if ($is_in_colors_bool) { if (stripos($offer['params']['color-material'], $_GET['s']) === false) { unset( $sections[ $section_key ] ); } } if ($is_in_types_bool) { if (stripos($offer['params']['case-type'], $_GET['s']) === false) { unset( $sections[ $section_key ] ); } } } } } } } } // Let's group by colors foreach( $sections as $sect=>$items ) { $key=0; foreach( $items as $item_name=>$variants ) { $colors = array(); foreach( $variants as $option ) { $colors[] = $option['params']['color-material']; } $full_set = $variants[0]; $full_set['colors'] = $colors; $new_sections[ $sect ][] = $full_set; $key++; } } $sections = $new_sections; $order = $_GET['order']; if( $order ) { if( $order == 'high' ) { foreach( $sections as $sect=>$items ) { usort($sections[$sect], function ($a, $b) {return $a['price'] < $b['price'];}); } } if( $order == 'low' ) { foreach( $sections as $sect=>$items ) { usort($sections[$sect], function ($a, $b) {return $a['price'] > $b['price'];}); } } } /* echo "
";
print_r($sections);
echo "
"; */ ?>

:



$products ) { ?>
2 ) { ?> style="display: none;" >