lundi 28 août 2017

Code to check if a post item is in a category keeps failing

I'm trying to add the name of a specific custom taxonomy to my shop loop on my website. I'm getting a few issues with my code and would like a bit of help if possible.

/*Add category name to loop*/

function trodproducttax() {
    global $product_id;
    global $post;
    $product_id = $post->ID;
    if ( in_category('men', $product_id) ) {
        echo 'Men ';
    }
    else {
        echo 'dunno';
    }

}
add_action(woocommerce_after_shop_loop_item, trodproducttax, 10);

I keep getting my logical test for the if statement failing even though some of the items in my loop do belong to the category Men. This seemed like a simple snippet when I started writing lol. Now not so much.

Aucun commentaire:

Enregistrer un commentaire