我需要检索所有版本的图片,我可以使用
$variation = wc_get_product( $variation_id );
$updated_image_id = $variation->get_image_id('edit');
获取第一张图片
但是如果我知道版本ID,该如何获取所有其他版本图像?
答案 0 :(得分:0)
您可以尝试-未测试。
$args = array(
'post_parent' => $variation_id,
'post_type' => 'attachment',
'post_mime_type' => 'image'
);
$images = get_children( $args );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
//Do whatever here
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
答案 1 :(得分:0)
您可以获得产品版本的列表:
// In the product loop:
$variations = $product->get_available_variations();
// Outside the product loop:
$product = new WC_Product_Variable( $product_id );
$variations = $product->get_available_variations();
环绕它以从每个变化中获取图像,如下所示:
foreach ( $variations as $variation ) {
echo $variation['image_src'];
}