Filtrar JetSmartFilters (Checkboxes List) de taxonomías añadir categoría con get_terms

Filtrar JetSmartFilters (Checkboxes List) de taxonomías añadir categoría con get_terms

Filtrar con get_terms desde JetSmartFilters (Checkboxes List) de taxonomías añadiendo una categoría de producto.

/**
* Filtrar get_terms
*/
function get_subcategory_terms( $terms, $taxonomies, $args ) {

if ( wp_doing_ajax() || is_admin() ) {
return $terms;
}

switch ( $taxonomies[0] ) {
case "pa_superficie":

$new_terms = array ();
$ceb = get_queried_object_id();
$products_id_terms = array ();

foreach ( $terms as $key => $term ) {
//echo "term<pre>"; print_r ($term); echo "</pre>";

$args_prod_in_term = array(
"post_type" => "product",
"post_status" => "publish",
"ignore_sticky_posts" => 1,
"posts_per_page" => "100000",
"tax_query" => array(
array(
"taxonomy" => "pa_superficie",
"field" => "term_id",
"terms" => array ( $term->term_id ),
"operator" => "IN"
),
array(
"relation" => "AND",
array(
"taxonomy" => "product_cat",
"field" => "term_id", //This is optional, as it defaults to "term_id"
"terms" => $ceb,
"operator" => "IN" // Possible values are "IN", "NOT IN", "AND".
),
array(
"taxonomy" => "product_visibility",
"field" => "slug",
"terms" => "exclude-from-catalog", // Possibly "exclude-from-search" too
"operator" => "NOT IN"
)
)
)
);

$featured_query = new WP_Query( $args_prod_in_term );
while ($featured_query->have_posts()) :
$featured_query->the_post();
//echo "product<pre>"; print_r ($featured_query->post->ID); echo "</pre>";
$products_id_term_item = $featured_query->post->ID ;

if ( ! in_array ( $term->term_id, $products_id_terms )) {
$products_id_terms[] = $term->term_id ;
$new_terms[] = $term;
}
endwhile;
wp_reset_query();
}

return $new_terms;



default:
return $terms;
}
}

add_filter( "get_terms", "get_subcategory_terms", 10, 3 );