A while ago I received this piece of code to hide categories that are not checked B2B. It works but strangely enough it skips some categories even if that categorie is unchecked for B2B. Is there some parameter that prevents the css class from being placed?
//B2B hide cats
function add_class_to_empty_category_menu_item($classes, $item) {
if ($item->object == 'product_cat') {
$category_id = $item->object_id;
$user_id = get_current_user_id();
$is_b2b = get_user_meta($user_id, 'b2bking_b2buser', true);
if ($is_b2b === 'yes'){
$group_id = get_user_meta($user_id, 'b2bking_customergroup', true);
$group_visibility = get_term_meta($category_id, 'b2bking_group_'.$group_id, true);
if (intval($group_visibility) === 0){
$classes[] = 'niksdrin'; // Add your custom class here
}
}
}
return $classes;
}
I've reviewed that code snippet but unfortunately I can't immediately identify why some categories would be skipped.
To help narrow this down - for categories that are being skipped (not getting the class when they should), could you try going to the backend category edit page and clicking Save/Update on those specific categories, and check if that fixes it? Sometimes the database settings for categories can get out of sync, and saving them resets those values. It would help us better understand the problem.
If that doesn't resolve it, I'd be happy to troubleshoot this directly on your site. For that, I'd need backend admin access to the site or a staging clone site. It would also help if you could point me to a specific example of a category that's not hiding properly when it should be.
Hello,
A while ago I received this piece of code to hide categories that are not checked B2B. It works but strangely enough it skips some categories even if that categorie is unchecked for B2B. Is there some parameter that prevents the css class from being placed?
Hi Marcel,
Glad to assist,
I've reviewed that code snippet but unfortunately I can't immediately identify why some categories would be skipped.
To help narrow this down - for categories that are being skipped (not getting the class when they should), could you try going to the backend category edit page and clicking Save/Update on those specific categories, and check if that fixes it? Sometimes the database settings for categories can get out of sync, and saving them resets those values. It would help us better understand the problem.
If that doesn't resolve it, I'd be happy to troubleshoot this directly on your site. For that, I'd need backend admin access to the site or a staging clone site. It would also help if you could point me to a specific example of a category that's not hiding properly when it should be.
Kind regards,
Stefan
hello,
i traced the problem; the links that failed where absolute links and not links directly linked to the category.
Thank you!