M
M
mr-ZA2019-05-11 20:29:52
WordPress
mr-ZA, 2019-05-11 20:29:52

WooComerce Wordpress product on different pages?

| Tools | Workwear | -- an example of a menu on the site
|_
Screwdrivers
Pliers
...
Hello everyone, I have a problem - I want to make sure that the goods (for example, screwdrivers) are placed not on the Tools page, but on the Screwdrivers page in the drop-down menu), the necessary pages have been created! The woocomerce plugin on the site has a product category item, but when you check the box next to the screwdriver page, the added product is still on the <Tools> parent page. In the future, more categories of goods are expected and I don’t want everything to be in one heap.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2019-05-11
@mr-ZA

Because the screwdriver belongs to the parent category by default, however, in the product category settings there is a category display type setting, select subcategories
if, in the parent category, there are products that do not belong to child categories, you can do this

#https://wordpress.stackexchange.com/questions/275213/remove-child-products-from-woocommerce-category-page#answer-275260
function exclude_product_cat_children( $wp_query ) {
    if ( isset( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query() ) {
        $wp_query->set( 
            'tax_query', array( array (
                'taxonomy' => 'product_cat',
                'field' => 'slug',
                'terms' => $wp_query->query_vars['product_cat'],
                'include_children' => false
            ) )
        );
    }
}  
add_filter('pre_get_posts', 'exclude_product_cat_children');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question