Reputation: 303
I have specific question about WooCommerce plugin.
I am using WooCommerce Product Categories
widget to show category menu on the left sidebar.
On my website I have a category for special offers (which contains some subcategories and products) and I want other categories to be hidden from Woocommerce Product Categories
widget when user opens this "Special Offers"
category.
I already tried to create custom sidebar to show only on this category but without luck.
How can I achieve this?
Maybe I can create two seperate widgets - one will display list of category "Special offers"
subcategories and second widget will display other categories & its subcategories but.. how to show these widgets with that kind of conditional logic?
Upvotes: 2
Views: 3726
Reputation: 10502
Unfortunately, none of the ways to solve the problem from StackOverflow worked:
I've tried to edit these files: archive.php (due to seeing "Archiwum..."
on https://sklep.atutdotacje.eu/kategoria-produktu/artystyczna/, so
thought maybe your theme reads category pages as archives), sidebar.php
,
and framework/modules/sidearea/templates/sidearea.php
. I've also looked
into framework/modules/sidebar/sidebar.php
&
framework/modules/sidearea/functions.php
.
There were many versions of the code I've tried on these .php files (that's the longest try):
<?php if ( is_active_sidebar( 'sidearea' ) || is_product_category() ||
is_archive() || is_product_category( 'zawody-przyszlosci' ) ||
is_product_category( array( 'zawody-przyszlosci', 'artystyczna' ) )) {
dynamic_sidebar( 'sidearea' );
} ?>
Trying to set up from Products -> Categories -> particular category option, is also not working. "Display type" doesn't solve the issue.
I found out while Googling my problem there are even articles on theme provider sites how to fix such a problem ttps://theme.co/forum/t/sidebar-not-showing-category-pages/48760/7
Therefore, I've reached out to my Theme provider, and they sent me an article, where I solved it in 5 minutes: https://helpcenter.qodeinteractive.com/hc/en-us/articles/360002245937-How-To-Set-Up-The-WooCommerce-Shop-Category-Sidebar-On-Your-Site
For me, it was:
Dashboard
> WooCommerce
> Settings
> Products:
Appearance
> Widgets
> and create a new Custom Widget Area
- (it needs to be a custom area):Shop
page in Dashboard
> Pages
, then locate and Edit the page
, scroll towards the bottom and find Choose Widget Area in Sidebar
. Now simply select your Area.Long story short: ask your theme provider how to do that.
Upvotes: 0
Reputation: 253804
---- Update (related to your comment) ----
You need to use the conditional is_product_category( 'my_category_slug' )
.
Reference: WooCommerce Conditional Tags
You should try then this, to include also all subcategories of your 'special_offers' category.
if ( is_product_category( 'special_offers' ) || is_product_category( array( 'my_sub_category1', 'my_sub_category2', 'my_sub_category3' ) ) ) {
// My custom side-bar code for "Special Offers" category
} else {
// My custom side-bar code for all other products
}
Fine tune (adding or removing subcategories) and replace 'my_subcategory1', 'my_subcategory2', 'my_subcategory3' by your subcategories slugs, please.
Upvotes: 1