How to hide a tag from a download page of Easy Digital Downloads

137 views Asked by At

I created a function to redirect all the products with the tag 'ABC' to a different page (for logged-out users only).

is_singular('download') && has_term(array('ABC'), 'download_tag')

The problem is that logged-in users can still access the page and see the 'ABC' tag in the tags list.

What's the function that I can add to the functions.php file that will only hide the ABC tag specifically?

Thank you

1

There are 1 answers

9
Kevin Marsden On

You can hook into get_object_terms to filter terms before they are displayed. Here's an example:

function custom_hide_terms( $terms, $object_ids, $taxonomies, $args )
{
    if ( !is_admin() ) {
        // note that we are filtering by the term slug, not the term name,
        // so be careful with "ABC" versus "abc"
        $exclude = array( 'ABC' );

        // Loop through terms and remove ABC
        if ( $terms ) {
            foreach ( $terms as $key => $term ) {
                if (is_object($term) && in_array( $term->slug, $exclude ) ) {
                    unset( $terms[$key] );
                }
            }
        }
    }
    return $terms;
}

add_filter( 'get_object_terms', 'custom_hide_terms', 10, 4 );