Filtrar JetSmartFilters añadiendo una categoría además de los filtros definidos

Filtrar JetSmartFilters añadiendo una categoría además de los filtros definidos.

function ebfilter_pre_get_posts( $query ) {
$ceb = $_SESSION["ceb"];
$term = get_term_by("slug", get_query_var("s"), "product_tag");
$tax_query = array(
"taxonomy" => "product_cat",
"terms" => array ( $ceb ),
"field" => "term_id",
"operator" => "IN",
);
$query->tax_query->queries[] = $tax_query;
$query->query_vars["tax_query"] = $query->tax_query->queries;
$query->set("tax_query", $query->tax_query->queries);
}



function ebfilter_products_shortcode_args( $args, $atts, $type ){
//echo "<pre>";print_r ($type);echo "</pre>";
if ( wp_doing_ajax() && $type === "products" ) {
add_action( "pre_get_posts", "ebfilter_pre_get_posts", 1 );
}
else {
remove_action( "pre_get_posts", "ebfilter_pre_get_posts", 1 );
}

return $args;
//echo "<pre>";print_r ($atts);echo "</pre>";
}

add_filter( "woocommerce_shortcode_products_query", "ebfilter_products_shortcode_args", 10, 3 );

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 );