PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Archive category disappears in body class when filter set

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hello,

When I'm on a WooCommerce category archive page, I can find the product category in CSS from the body classes (e.g. body.archive.tax-product_cat.term-shoes for Shoes category): https://prnt.sc/ub1oj7

But when I select a filter on the same page, I loose the information about the product category in the CSS: https://prnt.sc/ub1r0a

I need to get the category information somewhere in the CSS to style the elements based on the category. For example to hide the filters specific to other categories (below to hide the wear size filter on shoes category page):

body.archive.tax-product_cat.term-shoes .woof_container_pa_size-wear{
display: none;
}

Is there any way to keep the category information in the CSS when a filter is applied?

Thanks!

Hello

Please  try  this  option ->Advanced->Options - https://c2n.me/48Yc7jw.png and  do a test

Thanks for the reply. It doesn't seem to fix the issue, I'm loosing the category information in the body CSS classes.

I've added WooCommerce admin credentials and plugin purchase code in private data for this topic, can you please have a look?

 

Thanks!

Hello

Lets clarify the question:

  1. https://lacednew.wpengine.com/categorie-produit/shoes/?swoof=1&orderby=price&stock=instock&pa_pointures=37&really_curr_tax=23-product_cat
  2. https://lacednew.wpengine.com/categorie-produit/shoes/

Both of the in tag body has css classes:

  1. archive tax-product_cat term-shoes term-23 theme-laced-run-new woocommerce woocommerce-page woocommerce-js woof_search_is_going
  2. archive tax-product_cat term-shoes term-23 logged-in admin-bar theme-laced-run-new woocommerce woocommerce-page woocommerce-js customize-support

So do you mean loosing of the class: customize-support

Just remade and found that set of classes is equal, but with WOOF filtering appears one more class woof_search_is_going

Hi @realmag777 , thanks for having looked at the site. So the category classes seem to be kept when filtering by size (pointure), but the problem is when filtering by brand:

archive tax-pwb-brand term-avnier term-45 logged-in admin-bar theme-laced-run-new woocommerce woocommerce-page woocommerce-js woof_search_is_going customize-support

Hello

I found the reason, it is in CSS rule: https://clip2net.com/s/490GqAf

Add next rule:

body.archive .liste-produits__div .product-card2__image {
  object-fit: cover;
}

Current rule doesn work as it need CSS class 'tax-product_cat' which not generates on brands pages

 

Hi @realmag777 , this CSS rule should only be applied to products of the shoes category, that's why I want to get the category in the CSS when a filter is applied. Because the shoes product pictures don't have the same dimensions as other products and I want them to be covering instead of contained.

Is there any way to keep the category information somewhere in the CSS when a filter is applied by brands? The product category is still visible in the url when the filter is applied by brand so I would expect it to be in the CSS as well: https://prnt.sc/udmii4

Hello Julien

Yes, you can manipulate by css classes in tag body using next code in file functions.php of the current wordpress theme:

add_filter('body_class', function($classes, $class) {
global $WOOF;
if ($WOOF->is_isset_in_request_data($WOOF->get_swoof_search_slug())) {
if(isset($classes['tax-pwb-brand']))
$classes[] = 'your_css_class';
//unset($classes['your_css_class_2']);
}

return $classes;
}, 10, 2);

Hi @realmag777 !  Thank you! I am really not familiar with PHP code. So I would need to update this function to add a new class to the body tag (e.g. 'cat-shoes') when the page url contains 'really_curr_tax=23-product_cat'?

Feel free to add the code directly in the Code Snippet plugin in the Wordpress admin panel if it's faster and easier for you than explaining.

Thanks for your support, I really appreciate, I'll rate your plugin 5 stars wherever I can!

Hello Julien

I pasted code here: https://lacednew.wpengine.com/wp-admin/theme-editor.php?file=functions.php&theme=laced-run-new

Now products images has the same size: https://lacednew.wpengine.com/categorie-produit/shoes/?swoof=1&stock=instock&pwb-brand=adidas-original&really_curr_tax=23-product_cat

Hi @realmag777 , thank you, I understand what you've done but what I tried to explain is that now the images are all with object-fit:cover when a brand is selected, even for other categories like Wear: https://lacednew.wpengine.com/categorie-produit/vetements/?swoof=1&stock=instock&pwb-brand=adidas-original,carharttwip&really_curr_tax=18-product_cat

 

I need to set object-fit:cover to only pictures of the shoes category. Is it possible to update the function to add the custom class only when the category is Shoes (page url containing 'really_curr_tax=23-product_cat' or 'categorie-produit/shoes')?

Hello Julien

I hope this time I undertood you right: set CSS rule object-fit:cover  only for products on category page categorie-produit/shoes/ when brands selected

Examples:

Code changed on page https://lacednew.wpengine.com/wp-admin/theme-editor.php?file=functions.php&theme=laced-run-new to:

add_filter('body_class', function($classes, $class) {
global $WOOF;
if (is_object($WOOF)) {
if ($WOOF->is_isset_in_request_data($WOOF->get_swoof_search_slug())) {
if ($WOOF->is_isset_in_request_data('pwb-brand')) {
if ($WOOF->is_isset_in_request_data('really_curr_tax') AND intval($WOOF->get_request_data()['really_curr_tax']) === 23) {
$classes[] = 'term-shoes tax-product_cat';
}
}
}
}

return $classes;
}, 10, 2);

Hi @realmag777 ! Thanks yes this is what I need! Thank you very much for your help!!!

Welcome :)