• Resolved alfons271

    (@alfons271)


    Hi,

    I’m using the following code on woocommerce/templates/single-product/related.php to hide one category for being displayed on related products:

    $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),
    	'tax_query' => array(array(
    	'taxonomy' => 'product_cat',
    	'field' => 'slug',
    	'terms' => array( 'packs' ), // Don't display products in the packs category in related products
    	'operator' => 'NOT IN'))
    ) );

    And is hiding all categories and not only the “packs” one. I’m doing something wrong?

    By the way I’m making changes on the plugin file, I’ve tried to pars this code on functions.php of my child theme, but not working. Is there a way to use it there? or is better to use the hooks option?

    Any help would be much appreciated

    thanks

    https://www.ads-software.com/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    If there are not too many products in this category, you could exclude them by ID instead.

    'post__not_in' => array($product->id),

    Would become:

    'post__not_in' => array($product->id, 1, 2, 3 ),

    etc

    Thread Starter alfons271

    (@alfons271)

    Thanks for your reply, I have 6 or 7 categories with many products inside them.

    The one I want to exclude from related products is “packs”, but I see that I have other two categories named “packs love u” and “packs duo”.

    I realize that the

    'terms' => array( 'packs' ),

    is hiding the other two categories beginning with name “packs” so I ended up changing the name of those categories and problem solved.

    Anyway I would like to know how come this is happening.

    Thanks for your plugin and support,

    cheers

    This helped me a lot!

    But I need to hide 2 catagorys. How do I do that?

    I have entered:
    ‘terms’ => array( ‘kunde-pakker’ ),
    And this works fine, as in shown above

    But:
    ‘terms’ => array( ‘kunde-pakker, customer-bundle’ ),
    and
    ‘terms’ => array( ‘kunde-pakker; customer-bundle’ ),
    does not work. not on the “kunde-pakker” either

    How should I write the 2 catagorys besides each other?

    //Flofre

    Try each term enclosed in a ‘
    ‘terms’ => array( ‘kunde-pakker’, ‘customer-bundle’ ),

    @lorro

    That worked ??
    Thanks ??

    //Flofre

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide related product per category is hiding other categories’ is closed to new replies.