product gallery attachment url in woocommerce


Staff member
I'm using this snippet to output the product gallery attachments on a custom wordpress template for a woocommerce site. I'm using a lightbox for the popup. But I struggling to get the attachment url, instead it keeps on using the featured image the pop-up.

global $product;
$attachment_ids = $product->get_gallery_attachment_ids();

$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
$url = $thumb['0']; 

echo '<div>';
foreach( $attachment_ids as $attachment_id ) 
echo '<a href="' . $url . '" rel="shadowbox" >' ."<img src=".$image_link = wp_get_attachment_url( $attachment_id, 'large')." style='width:70px; height:70px;' >". '</a>';
echo '</div>';

Any ideas on how to target the correct url path for the product gallery images?
Any help much appreciated!