// the snippet from ismael 

function avf_view_product_button_to_masonry_entry($content, $entry, $config) { 
    $custom_link = get_post_meta($entry['ID'], 'av-custom-link', true);
    $product_link = !empty($custom_link) ? $custom_link : get_permalink($entry['ID']);

    $view_product_button_html = "<div class='view-product-button'>
        <span href='" . esc_url($product_link) . "' class='button popup-modal-dismiss' title='" . esc_attr(get_the_title($entry['ID'])) . "'>
            View Product
        </span ></div>";

    $content .= $view_product_button_html;
    return $content;
}

add_filter('avf_masonry_entry_content', 'avf_view_product_button_to_masonry_entry', 10, 3);
function product_link_via_lightbox() {
if(is_page(45458)){
?>
<script type="text/javascript">
(function($){

    $('.av-masonry.image-first-then-page a').magnificPopup({
    type: 'image',
    removalDelay: 500,  // to allow animated closing in ms
    mainClass: 'avia-popup mfp-3d-unfold',   // hier jetzt die Animationsklasse - siehe Dmitry Semenov Seite 
    midClick: true,
    gallery: { enabled:true },  
    callbacks: {
		elementParse: function(item) {
			var bgImage = item.el.find('.av-masonry-image-container').css('background-image').replace(/^url\(['"]?/,'').replace(/['"]?\)$/,'');
			item.src = bgImage;
		},

		beforeOpen: function() { 
		 this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
		},  
		markupParse: function (template, values, item) {

			if ( item.el.find('.view-product-button').length ) {
			  var buttonLink = item.el.find('.button').attr('href');
			  values.title = '<h3>' + item.el.find('.av-masonry-entry-title').html()+ '</h3>' + '<span class="avia-button-wrap glass blue" style="float:right"><a href="' + buttonLink + '" class="avia-button av-link-btn avia-icon_select-yes-right-icon avia-size-medium avia-position-center av-icon-on-hover avia-color-light popup-modal-dismiss" aria-label="Show Product"><span class="avia_iconbox_title">Show Product</span><span class="avia_button_icon avia_button_icon_right" aria-hidden="true" data-av_icon="" data-av_iconfont="entypo-fontello"></span></a></span>';
			} 
			else {
			  values.title = '<h3>' + item.el.find('.av-masonry-entry-title').html() + '</h3>';
			}

		},
	},
  });

})(jQuery);
</script>
<?php
}
}
add_action('wp_footer', 'product_link_via_lightbox', 9999);
#top.page-id-45458 .mfp-title h3 {
  position: absolute;
  float: left;
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
}

.view-product-button {
  display: none;
}

#top .mfp-content .avia-button-wrap.glass {
  margin: 0px !important;
}