In the related products section, I would like to filter out certain products. I cannot simply hide these products from the shop as I want to use them in the up-sells section.

In the related.php file, is there any argument I can use to filter out certain products? The products I want to filter, all contain the word “set” in them, and they also have a class “setBadge”. Can I use these to somehow filter them out? (I cannot use css for this as if I use display: none they leave an empty space, I want to exclude them from the loop).

$args = apply_filters('woocommerce_related_products_args', array(
    'post_type'             => 'product',
    'ignore_sticky_posts'   => 1,
    'no_found_rows'         => 1,
    'posts_per_page'        => $posts_per_page,
    'orderby'               => $orderby,
    'post__in'              => $related,
    'post__not_in'          => array($product->id)
) );

Read more here: In Woocommerce, filter out certain related products by text or class


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: