I'm designing template from scratch in WordPress, I am having a problem on getting product images/Gallery on single.php by product ID; here's my code:
function GetImageUrlsByProductId( $productId){
$product = new WC_product($productId);
$attachmentIds = $product->get_gallery_image_ids();
$imgUrls = array();
foreach( $attachmentIds as $attachmentId )
{
$imgUrls[] = wp_get_attachment_url( $attachmentId );
}
return $imgUrls;
}
$id = the_ID();
echo $id."<br/>";
$title = get_the_title();
echo $title."<br/>";
print_r(GetImageUrlsByProductId($id));
It showed empty array, but I want images path.