Home Forums Basel support forum Exclude Product Category from shop page

Exclude Product Category from shop page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10723

    viqtor
    Participant

    Im trying to remove a particular category “knives” from the shop page using this piece of code from the woo commerce documents whilst it does remove the product it renders the filter widgets on the left hand side inoperable clicking on any filter just returns all items to shop.

    I also want the products within knives to remain hidden even if a filter is selected in the shop page which relates to them. However I want them to show when using XTEMOS Product category.

    ultimately what i am try to achieve is to have a category to appear only on its on page and not within the general shop.

    add_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );

    function custom_pre_get_posts_query( $q ) {

    if ( ! $q->is_main_query() ) return;

    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() && is_shop() ) {

    $q->set( ‘tax_query’, array(array(

    ‘taxonomy’ => ‘product_cat’,

    ‘field’ => ‘slug’,

    ‘terms’ => array( ‘knives’ ), // Don’t display products in the knives category on the shop page

    ‘operator’ => ‘NOT IN’

    )));

    }

    remove_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );

    }

    #10738

    Artem Temos
    Keymaster

    Hello,

    Thank you for choosing our theme and contacting us.

    Sorry, but this question is related to WooCommerce plugin and is out of our theme support scope. According to Envato Support Policy, theme support doesn’t include any additional customization with third party plugins.

    Kind Regards
    XTemos Studio

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)