How to add categories to category and subcategory page on WooCommerce - Wordpress

Asked
Active3 hr before
Viewed126 times

4 Answers

90%

On the right pane, you will find the list of all categories,Go to Dashboard > Products > Categories,Click on any category you want to edit and it will take you to Edit Product Category page,Select the parent category of this category from Parent category drop-down

remove_action('woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10);
load more v
88%

If you file a post under the child category but not under the parent category, then your post will appear only on the archive pages of the child category. This is particularly helpful when you want to avoid duplicate content. ,If you mean when adding a post to the category, you would only need to check the child category,A post filed under a child category doesn’t need to also be filed under the parent category. In our example, we could have left ‘United States’ unchecked and just put the post in the ‘New York City’ category.,A category will not appear on your site until you publish a post in that category.

Your category URLs will look something like this:

http://example.com/category/united-states/new-york-city/

http: //example.com/category/united-states/new-york-city/
load more v
72%

Identify the code WooCommerce uses to output categories and subcategories on archive pages.,Now, let's take a look at how WooCommerce displays the product categories and products on archive pages.,WordPress 25+ Best WooCommerce Plugins for Products, Pricing, Payments, and More Eric Dye,But before you start, you'll need a WooCommerce installation with some products added and product categories and subcategories set up.

Inside that file, you can find this code, which outputs the categories and products:

< ? php
/**
 * woocommerce_before_shop_loop hook
 *
 * @hooked woocommerce_result_count - 20
 * @hooked woocommerce_catalog_ordering - 30
 */
do_action('woocommerce_before_shop_loop'); ?
>

<
? php woocommerce_product_loop_start(); ? >

<
? php woocommerce_product_subcategories(); ? >

<
? php
while (have_posts()): the_post(); ? >

<
? php wc_get_template_part('content', 'product'); ? >

<
? php endwhile; // end of the loop. ?>

<
? php woocommerce_product_loop_end(); ? >
load more v
65%

With WooCommerce by default, it is possible to select whether your category pages display products, subcategories or both products and subcategories and this can be adjusted in Appearance >> Customize >> WooCommerce >> Product Catalog:,Also when I click on that subcategory it showing me subcategories and products all together but I want it to be separated from one another. Please guys, if anyone has a good will to help me out it’ll make my day.,Support » Plugin: WooCommerce » Subcategories are showing with the categories and products.,If you’d like to display both products and subcategories but have those separated – you’ll probably have to customize the code of the extension or hire a developer.

I want to tell you that I’ve found a solution with this code added in my function.php
I thought it may be helpful for someone who have the issue like me.

/**
* Move WooCommerce subcategory list items into
* their own <ul> separate from the product <ul>.
*/
add_action( 'init', 'move_subcat_lis' );
function move_subcat_lis() {
	// Remove the subcat <li>s from the old location.
	remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
	add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_start', 1 );
	add_action( 'woocommerce_before_shop_loop', 'msc_maybe_show_product_subcategories', 2 );
	add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_end', 3 );
}
/**
 * Conditonally start the product loop with a <ul> contaner if subcats exist.
 */
function msc_product_loop_start() {
	$subcategories = woocommerce_maybe_show_product_subcategories();
	if ( $subcategories ) {
		woocommerce_product_loop_start();
	}
}
/**
 * Print the subcat <li>s in our new location.
 */
function msc_maybe_show_product_subcategories() {
	echo woocommerce_maybe_show_product_subcategories();
}
/**
 * Conditonally end the product loop with a </ul> if subcats exist.
 */
function msc_product_loop_end() {
	$subcategories = woocommerce_maybe_show_product_subcategories();
	if ( $subcategories ) {
		woocommerce_product_loop_end();
	}
}
load more v

Other "undefined-undefined" queries related to "How to add categories to category and subcategory page on WooCommerce - Wordpress"