php 获取所有变体图像(附加变体图像woocommerce插件)

dffbzjpn  于 5个月前  发布在  PHP
关注(0)|答案(2)|浏览(53)

我需要检索一个变体的所有图像,我可以用$variation = wc_get_product( $variation_id ); $updated_image_id = $variation->get_image_id('edit');获取第一个图像,但如果我知道变体ID,我如何获取所有其他变体图像?

brc7rcf0

brc7rcf01#

你可以试试这个-但没有测试过。

$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' );
    }
}

字符串

mi7gmzs6

mi7gmzs62#

你只需要传递$variable_id

//displays thumbnail picture
echo "<img src=" . wp_get_attachment_url($product->get_image_id()) . " />"; 

//displays other pictures from WooCommerce Additional Variation Images
$imagesIDS = get_post_meta($variable_id, '_wc_additional_variation_images', true ); 
$imagesArray = explode(",", $imagesIDS);
foreach ($imagesArray as $imageID) {
    echo wp_get_attachment_image( $imageID, 'full' );
}

字符串

相关问题