• Resolved alexis888

    (@alexis888)


    Hello.
    I’m trying to hide a specific category term (“Preorder” + the coma “,”) in the meta data of a product on a single product page, in the product archive page and “related product” loop too.

    Each product belongs to only one category ( Merch, Records, Print or Goodies) and sometimes to the Preorder category as well. I never want the “Preorder” category term to be displayed in meta data.

    I’ve been trying to tweak the meta.php file in my child theme but couldn’t make it work.
    I also thought about using CSS to display:none the span:last-of-type but since the category terms are displayed in alphabetical order it doesn’t work as I have some categories like “Print”.

    I think there might be a solution with filter hooks in my functions.php but I don’t have enough knowledge to find the solution.

    Any idea how I could do that ?

    I’m working on a local environnement atm so here is a pic to show what I want to remove: https://ibb.co/znkwH41

    Thanks !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @alexis888,

    Sincere apologies for the extremely long wait, we have been a bit shorthanded and on the other hand overwhelmed with work during this covid situation.

    We are using the default woocommerce_template_single_meta() function, so it would be best to reach out to respective WooCommerce support and ask them if they have any kind of snippet which would allow you to exclude specific categories from the single post meta.

    Hope this helps. Best of luck with your website

    Thread Starter alexis888

    (@alexis888)

    Hello, no worries. I’m actually using Rank Math and their support provided me a solution which is :

    Here is a complete code:

    add_filter( 'term_links-product_cat', function( $links ) {
    	return [ $links[0] ];
    });

    Please add this code to your theme’s functions.php file.

    You can further filter it, so say for e.g. if you want to show the primary category only on page with ID 1, then you can use is_page( 1 ) condition.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide specific category term in product meta’ is closed to new replies.