最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - How to list all WC products by their attributes values?

programmeradmin1浏览0评论

I wanted to get some advice on how to list all my inventory attributes values. I have this simple code that will output the products as plain text, But instead of the_title(); I want a list of all products by their attribute's values. So, if a product has attribute carat it will be listed as follows:

carat 
0.32
0.41
2.3
3.3

A product has attribute color and another product has attribute carat and they will be listed as

red
0.32
blue
0.32
0.41
2.3
3.3

Basically, I want to know how to do it for multiple attributes to get their values, cuz bottom line the title of my products are the same values concatenated together.

Right now, I am only getting a list of titles, but I want a list of attributes' values.

<?php
    $params = array('posts_per_page' => 5, 'post_type' => 'product'); 
    $wc_query = new WP_Query($params); 
?>
<?php if ($wc_query->have_posts()) :  ?>
<?php while ($wc_query->have_posts()) : $wc_query->the_post();  ?>

<?php the_title();?><br>


<?php endwhile; ?>
<?php wp_reset_postdata();  ?>
<?php else:  ?>
    <p><?php _e( 'No Products' );  ?></p>
<?php endif; ?>

Thanks all for viewing this.

发布评论

评论列表(0)

  1. 暂无评论