[Resolved] Woocommerce exclude products from shop – workshops

Home Forums Support [Resolved] Woocommerce exclude products from shop – workshops

Home Forums Support Woocommerce exclude products from shop – workshops

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #593397
    _blank

    Hi
    I’m trying to remove 2 categories from the shop landing page using a PHP snippet from woocommerce.
    https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/

    The 2 product categories/slugs are events and workshops

    The snippet is here:

    /**
    * Exclude products from a particular category on the shop page
    */
    function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( ‘tax_query’ );

    $tax_query[] = array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘workshops’ ), // Don’t display products in the workshops category on the shop page.
    ‘operator’ => ‘NOT IN’
    );

    $q->set( ‘tax_query’, $tax_query );

    }
    add_action( ‘woocommerce_product_query’, ‘custom_pre_get_posts_query’ );

    #593534
    Leo
    Staff
    Customer Support

    Hi there,

    So the code isn’t working?

    Have you checked with WooCommerce’ support on this?

    The code is from them.

    #595134
    _blank

    Hi Leo

    I had a look but can’t find support options for their free plugins. Will try to contact them again.
    Do you have any ideas/suggestions on how I might achieve the same results. I’m using Beaver Builder to display the Categories.

    Thanks
    Scott

    #595299
    David
    Staff
    Customer Support

    Hi Scott, i tried the code for a single category on a non pagebuilder shop and it works. So must be a BB thing. Woo don’t really provide support for their free stuff. If you’re using the BB module, then this may help:

    https://kb.wpbeaverbuilder.com/article/79-woocommerce-module-overview#multiple-products

    #595317
    _blank

    Hi David

    Thats really helpful – I’ll contact BB and try a GP page as well for the Shop.
    Scott

    #595320
    David
    Staff
    Customer Support

    You’re welcome Scott.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.