P
P
proclub2020-06-15 01:59:54
WordPress
proclub, 2020-06-15 01:59:54

How to hide certain WooCommerce products only on the catalog page?

The bottom line is that on the main page (aka the catalog) not rubrics (categories) are included, but goods (all), there is another page on it, categories of the same kind are displayed. But they shouldn't be in the directory.
How can they be hidden?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stas Khitrich, 2020-06-15
@Snova_s_vami

Redefine the file responsible for displaying products, in theory this is archive_products, insert the is_shop check there and if this is a catalog page, then change it as you please. For example, insert a check and compare the category of each product already taken in advance by WooCommerce with the desired category or score on these products, make a request with filtering and take the necessary products that are not included in a specific category

A
akatonov, 2021-03-04
@akatonov

Assign a tag to the product you want to hide. and paste the code into your function.php

function exclude_specific_tag( $q ) {
    if (is_shop()){
        $tax_query = (array) $q->get( 'tax_query' );
        $tax_query[] = array(
            'taxonomy' => 'product_tag',
            'field' => 'slug',
            'terms' => array( 'Пробный' ), // Укажите наименование метки
            'operator' => 'NOT IN'
        );
        $q->set( 'tax_query', $tax_query );
    }
}
add_action( 'woocommerce_product_query', 'exclude_specific_tag' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question