Site logo

Archived topic

Conditionally hide products on woocommerce shop

3 replies · Started by Raul on September 19, 2020

Viewing posts 1–4 of 4

Hi team,

I found this old David's topic https://generatepress.com/forums/topic/conditional-formatting-of-woo-product-by-category/ while looking to hide products based on a ACF conditional (true/false). Following your example, I am able to add a class to hide products via CSS, but my issue is that the product pagination is of course not affected; Let's say I have 60 products per page, and when I hide 40 products with CSS, I still get page 1, 1-60 results, but only 20 are being displayed in the first page.

// Add class to not-sold-individually products - To hide via CSS
function tdp_category_id_class( $classes ) {
    global $post;
		
	if ( get_field( 'artwork_not_for_sale_alone' ) ) {
        $classes[] = 'not-sold-separately';
    }
    return $classes;
}
add_filter( 'post_class', 'tdp_category_id_class' );

Can you think of any solution for this? I believe I could use pre_get_post but don't really know how to use it with the shop.

https://developer.wordpress.org/reference/hooks/pre_get_posts/#utm_medium=referral&utm_source=facebook.com&utm_content=social

Glad to be of help.
Probably possible to have the ACF field add the Tax term for you - maybe ACF support has an answer for that.

This archived topic is closed to new replies.