对于一个特殊的画廊,我需要显示所有的woocommerce变异图像。在woocommerce content-single-product.php上,我可以访问变体,但我无法从中获取图像网址。我怎么能这样做?
在我的内容中 - single-product.php覆盖:
<?php
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => $post->ID
);
$variations = get_posts( $args );
echo "<pre>"; print_r($variations); echo "</pre>";
?>
答案 0 :(得分:0)
你可以这样做。
$product = new WC_Product_Variable( $product_id );
// get the product variations
$product_variations = $product->get_available_variations();
if ( !empty( $product_variations ) ) {
foreach($product_variations as $product_variation) {
echo $product_variation['image_src'];
}
}