WooCommerce:向产品库添加额外的图像

WooCommerce: add extra images to product gallery

我想在产品图库中添加一些额外的图片。基于来自不同 post 的元字段。图片应该只添加到前端的图库中。不是产品本身的图片库。

编辑:@mujuonly 是对的。我可以使用 woocommerce_product_thumbnails 所以我尝试了以下代码并且一切正常:

<?php 
add_action( 'woocommerce_product_thumbnails', 'custom_product_add_thumbnails', 100, 0 );
function custom_product_add_thumbnails(){
    
        $extra_gallery          = get_field( 'some_field' );
    
        if( $extra_gallery ): ?>
    
            <?php foreach ( $extra_gallery as $image_id ): ?>
                
                <div class="woocommerce-product-gallery__image">
                    <?php echo wp_get_attachment_image( $image_id, 'woocommerce_single', false, array( "class" => "" ) ); ?>
                </div>
            <?php endforeach; ?>
                
        <?php endif;
        
    endif; 
               
}

在动作中使用 100,图像显示在画廊的末尾:

add_action( 'woocommerce_product_thumbnails', 'custom_product_add_thumbnails', 100, 0 );
add_action( 'woocommerce_product_thumbnails', 'custom_product_add_thumbnails', 100, 0 );
function custom_product_add_thumbnails(){
    
       // Echo images here
               
}