Connected template category to product in bundle product search

This commit is contained in:
Nedim Uka
2018-10-23 15:48:56 +02:00
parent 18f40d9403
commit 66452eee86
5 changed files with 42 additions and 11 deletions

View File

@@ -44,6 +44,14 @@ class Wiaas_Admin_Product_Additional_Info {
}
}
/**
* This method filters search results by template country
* In addition it adds template category to label of every product
*
* @param $search_results array provided by filter
* @return mixed array of filtered search results
*/
public static function filter_product_by_country($search_results) {
$url = wp_get_referer();
@@ -59,9 +67,14 @@ class Wiaas_Admin_Product_Additional_Info {
if (!empty($search_results)) {
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
foreach ($search_result_objects as $result_id => $producta) {
if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) {
unset($search_results[$producta->get_id()]);
foreach ($search_result_objects as $result_id => $product_form_search) {
if (Wiaas_Countries::get_product_country_term_id($product_form_search) !== $country_id) {
unset($search_results[$product_form_search->get_id()]);
} else {
$template_category = wp_get_object_terms($product_form_search->get_id(), 'template_category', array('fields' => 'names'));
if(!empty($template_category)){
$search_results[$product_form_search->get_id()] = $search_results[$product_form_search->get_id()].'-'.$template_category[0];
}
}
}
}