Open WordPress Gallery Images In Lightbox

Woo Commerce already uses Pretty Photo for the product gallery and the product image. When you add a WordPress gallery to the product description the images don’t open using the Pretty Photo Lightbox. So I set on a mission to open WordPress gallery images in a lightbox. According to the Pretty Photo documentation all I needed to do was add the “rel attribute” to each image link. Originally I was looking for a filter to alter the gallery output. I ended up filtering “wp_get_attachment_link” to edit the image link. After viewing the code for the product gallery and the product image I realized I needed to add a “data-rel attribute”. The code I used is below.

add_filter('wp_get_attachment_link', 'ccr_add_rel_attribute');
function ccr_add_rel_attribute($link) {
    $link = str_replace('<a href','<a data-rel="prettyPhoto[gallery]" href',$link);
    return $link;

Solution Inspired by corsonr