Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce get image galleries by product id

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;  

?>
like image 511
Sergio R Sergi Avatar asked May 17 '16 11:05

Sergio R Sergi


People also ask

How do I get product image by product ID in WooCommerce?

This can be very useful if you need to display the product image on another website or blog post. To get started, simply go to WooCommerce > Settings > Products. From here, select the Display tab and then check the Enable Product Image By Product ID checkbox.

How do I get product gallery images in WooCommerce programmatically?

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 .

How do I get single product image in WooCommerce?

WooCommerce lets you resize the product images on Single Product and Shop pages from Appearance > Customize > WooCommerce > Product Images.

What are product gallery images in WooCommerce?

Product Gallery Slider for WooCommerce lets you easily present WooCommerce product images in a beautiful way. It gives you access to all the features and functionalities you might need in a product slider. Key features: It offers a responsive layout so your customers can scroll and navigate through your product pages.


1 Answers

I have already tested this and it works

<?php
    $product_id = '14';
    $product = new WC_product($product_id);
    $attachment_ids = $product->get_gallery_image_ids();

    foreach( $attachment_ids as $attachment_id ) 
        {
          // Display the image URL
          echo $Original_image_url = wp_get_attachment_url( $attachment_id );

          // Display Image instead of URL
          echo wp_get_attachment_image($attachment_id, 'full');

        }
?>
like image 90
Mash R. Avatar answered Sep 30 '22 16:09

Mash R.