• ok I am trying to retrive the category name of a woocommerce product displayed in a wordpress loop and use it as the class for a li also inside the loop i’ve tried this:

    <div id="isocontent" class="products">
    
    <ul><?php while (have_posts()) : the_post(); ?>
    
                                <li class="<?php echo $product->get_categories(); ?> box">
                                    <a>"><?php echo the_post_thumbnail(); ?></a>
                                    <p><a>"><?php the_title(); ?></a></p>
                                    <a>"><span href="<?php the_permalink(); ?> " class="amount price" data-original="<?php echo get_woocommerce_currency(); ?><?php echo $product->get_price(); ?>" data-price="<?php echo $product->get_price(); ?>" title="Original price: <?php echo $product->get_price(); ?>"><?php echo get_woocommerce_currency(); ?><?php echo $product->get_price(); ?></span></a>
                                    <a>?add-to-cart=<?php echo $post->ID ?>" class="pbutton">Add to Cart</a>
    
                            <?php endwhile; ?>
                        </ul>
                    </div>

    this being the part i’m trying to retrive the class with:

    <li class="<?php echo $product->get_categories(); ?> box">

    but it just outputs this:

    <li class="<a href=" http:="" localhost.no="" fanny="" kategori="" interior-sv="" "="" rel="tag">

    which does retrieve the category but also screws with the markup breaking the loop.
    I’ve also tried this:

    <li <?php post_class(‘box’); ?>

    but because woocommerce uses taxonmys it retrives the tags but not the product category.
    any help is much appriciated
    Kind regards
    Chris

  • The topic ‘woocommerce retriving category name as div class?’ is closed to new replies.