PressTigers

Dynamically Setting Display Type for Categories in WooCommerce

WooCommerce provides three types of display for content on category’s detail page such as Products, Subcategories, Both. By default, one of these three types is already selected. To change it, you can set another option from WooCommerce settings under Products tab. Additionally, you can set different options for each category. In this article, you will learn to set any one option dynamically without going to WooCommerce settings.

At first, you need to divide categories into two major ones like Parent and Children categories. Under child category page, you will be able to display products listing. Whereas under Parent category page, you will be able to display child categories.

In order to achieve this goal, you will use WordPress get_term_metadata filter. To access term meta, this filter is hooked with pt_set_category_display function in order to check if the category is either parent or child. Now, add the following code in your Theme‘s functions.php file or use it in your custom plug-in:

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

    Get in Touch