获取第一个缩略图的默认可变产品图片

时间:2019-03-04 18:41:03

标签: php wordpress woocommerce

希望使用默认的产品变化图片作为图库中的第一个缩略图。

我已经修改了product-thumbnails.php,但我已经关闭了,但仅需要将默认的变化图片显示为$image,现在,当前设置会显示所有产品变化图片,并且它们不在$image下有识之士将不胜感激。

global $product;
$post_thumbnail_id = $product->get_image_id();

if( wpgs_woocommerce_version_check() ) {
// Use new, updated functions
 $attachment_ids = $product->get_gallery_image_ids() ;
} else 
{
// Use older, deprecated functions
 $attachment_ids = $product->get_gallery_attachment_ids() ;
}

 $gallery_thumbnail = wc_get_image_size('gallery_thumbnail');
$thumbnail_size =apply_filters('woocommerce_gallery_thumbnail_size',           
array($gallery_thumbnail['width'], $gallery_thumbnail['height']));

if ( $attachment_ids && has_post_thumbnail() ) {
echo '<div class="wpgs-nav">';


$image_size = array(500,600);
$variation_image_id = array();
$attachment_ids = $product->get_gallery_image_ids();
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
}
$attachment_ids =   array_merge(    $variation_image_id ,      
$attachment_ids);

$post_thumbnail_id = $product->get_image_id();


echo '<div>'.$image.'</div>';

foreach ( $attachment_ids as $attachment_id ) {

     $thumbnail_image     = wp_get_attachment_image($attachment_id,    
$thumbnail_size);

          echo '<div>' . $thumbnail_image . '</div>';

}
echo "</div>";

}
}

0 个答案:

没有答案