Public Ticket #4505210

hiding categories

Closed
Comments
9 Tickets 2
Marcel started the conversation 12 months ago on October 13, 2025 at 3:01pm

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?

//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;
}
2,762
KingsPlugins replied 12 months ago on October 14, 2025 at 10:48pm

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

2,762
KingsPlugins replied 12 months ago on October 15, 2025 at 11:55pm

Ah, that makes sense! Great to hear you figured it out.

If you run into any other issues or anything we can help with, please let us know.

Kind regards,
Stefan

Sign In