• Resolved marcosvicentee

    (@marcosvicentee)


    I’m looking for a way to hide products of a specific categories (packs, liquor) on specific pages (Example: Hide packs and liquor in the “wines” page). I don ‘t want to hide them in my entire shop, only in the specified pages.

    I searched and another user tried this code and worked for him, but unfortunaly doesnt work on my webpage.

    add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
    /**
     * Hide Product Cateories from targetted pages in WooCommerce
     * @link https://gist.github.com/stuartduff/bd149e81d80291a16d4d3968e68eb9f8#file-wc-exclude-product-category-from-shop-page-php
     *
     */
    function prefix_custom_pre_get_posts_query( $q ) {
    	
    	if( is_page('wines') ) { // set conditions here
    	    $tax_query = (array) $q->get( 'tax_query' );
    	
    	    $tax_query[] = array(
    	           'taxonomy' => 'product_cat',
    	           'field'    => 'slug',
    	           'terms'    => array( 'packs, liquor' ), // set product categories here
    	           'operator' => 'NOT IN'
    	    );
    	
    	
    	    $q->set( 'tax_query', $tax_query );
    	}
    }

    What i am doing wrong?

    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide products of a category in the “all products” block in a certain page’ is closed to new replies.