我正在使用Woocommerce插件的最新产品短代码,它返回产品图片,标题和价格。我的所有产品都有更多属性,我也希望退回。我怎样才能做到这一点?
答案 0 :(得分:0)
我会创建一个这样的自定义循环:
https://www.philowen.co/blog/show-latest-woocommerce-products-in-your-template/
将其创建为自定义短代码或操作,具体取决于您计划将其置于何处并使用循环内的产品类提取属性:
<?php
$product = new WC_Product;
$attributes = $product->get_attributes();
foreach loop...
?>
类似的东西:
<?php
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 4,
'orderby' =>'date',
'order' => 'DESC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
global $product;
// Get the attibutes
$attributes = $product->get_attributes();
// Loop and display the value
// var_dump $attributes to see what you can output
foreach ($attributes as $attribute) {
echo $attribute['value'];
}
<?php endwhile; ?>
<?php wp_reset_query(); ?>