How to show images from the product gallery programmatically? I see the option to show featured images; but not to show all images for a product id.
Is it possible to do this?
I try this but couldn’t get the images from the product gallery by id in Woocommerce.
<?php
$gallery = get_post_gallery_images(724);
$image_list = '<ul id="cfImageGallery">';
foreach( $gallery as $image ) {// Loop through each image in each gallery
$image_list .= '<li><img src=" ' . str_replace('-150x150','',$image) . ' " /></li>';
}
$image_list .= '</ul>';
echo $image_list;
?>
I have already tested this and it works
Just to clarify, the above answers will get all but the thumbnail (main) image.
To prepend the thumbnail, use this:
//This adds the thumbnail id as the first element of the array
Use the
get_gallery_image_ids()
for get the Gallery Attachment Ids becauseget_gallery_attachment_ids()
deprecated since WooCommerce 3.0.0