Exclude specific categories from filter bar menu for non logged in users

Home Forums Calendar Products Filter Bar Exclude specific categories from filter bar menu for non logged in users

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1329328
    Nicolas
    Participant

    Can I hide specific categories from filter bar for the user there not logged in ?
    I habe use this code to hide the categories but it hide for all users.

    /* Tribe hide categories from filter */
    function tribe_modify_category_filter ( $values, $slug ) {

    if ( $slug != ‘eventcategory’ ) return $values;

    foreach ( $values as $key => $value ) {

    if ( $value[‘name’] == ‘Category Name’ || $value[‘name’] == ‘Category Name 2’ ) {

    unset( $values[$key] );

    }
    }

    return $values;

    }
    add_filter( ‘tribe_events_filter_values’, ‘tribe_modify_category_filter’, 10, 2 );

    • This topic was modified 6 years, 9 months ago by Nicolas.
    • This topic was modified 6 years, 9 months ago by Victor.
    #1330490
    Victor
    Keymaster

    Hello Nicolas!

    Thanks for getting in touch with us! I’d be happy to help with that.

    Try using the following code instead:

    /* Tribe hide categories from filter for not logged in users only */
    function tribe_modify_category_filter_not_logged_in ( $values, $slug ) {
    
    if ( is_user_logged_in() ) {
    return $values;
    }
    
    if ( $slug != 'eventcategory' ) return $values;
    
    foreach ( $values as $key => $value ) {
    
    if ( $value['name'] == 'Category Name' || $value['name'] == 'Category Name 2' ) {
    
    unset( $values[$key] );
    
    }
    }
    
    return $values;
    
    }
    add_filter( 'tribe_events_filter_values', 'tribe_modify_category_filter_not_logged_in', 10, 2 );

    I hope it helps! 🙂

    Best,
    Victor

    #1330675
    Nicolas
    Participant

    Thanks

    Best Regard

    Nicolas

    #1330837
    Victor
    Keymaster

    You’re welcome Nicolas!

    Don’t hesitate to open a new topic if anything comes up 🙂

    Cheers,
    Victor

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Exclude specific categories from filter bar menu for non logged in users’ is closed to new replies.