我需要检索一个变体的所有图像,我可以用$variation = wc_get_product( $variation_id ); $updated_image_id = $variation->get_image_id('edit');获取第一个图像,但如果我知道变体ID,我如何获取所有其他变体图像?
$variation = wc_get_product( $variation_id ); $updated_image_id = $variation->get_image_id('edit');
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' ); } }
字符串
mi7gmzs62#
你只需要传递$variable_id:
$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' ); }
2条答案
按热度按时间brc7rcf01#
你可以试试这个-但没有测试过。
字符串
mi7gmzs62#
你只需要传递
$variable_id
:字符串