Home Wordpress Tricks Woocommerce get product gallery images url

Woocommerce get product gallery images url

by therichpost
0 comment
How to add custom meta title and meta description in Wordpress?

Hello, welcome to therichpost.com. In this post, I will tell you How to get Woocommerce product gallery images url? WordPress is the best cms like I always say. In wordpress custom query post, we will get Woocommerce product gallery images url.

<?php

$args = array(
‘post_type’ => ‘product’
);

// Custom query.
$query = new WP_Query( $args );

// Check that we have query results.
if ( $query->have_posts() ) {

// Start looping over the query results.
while ( $query->have_posts() ) {

$query->the_post();

// Contents of the queried post results go here.
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
/*gallery Images code*/
foreach( $attachment_ids as $attachment_id )
{
$image_link = wp_get_attachment_url( $attachment_id );
}
/*gallery Images code*/

}

}

// Restore original post data.
wp_reset_postdata();

?>

There are so many tricky code in wordpress and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.