Created
January 7, 2020 18:46
-
-
Save morvy/a09122bbca8aea18f0fc4992323856ae to your computer and use it in GitHub Desktop.
Function override of flatsome_wc_get_gallery_image_html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function override for Flatsome theme | |
* - disables main image link on product page | |
* | |
* @param integer $attachment_id | |
* @param bool $main_image | |
* @param string $size | |
* @return string | |
*/ | |
function flatsome_wc_get_gallery_image_html( $attachment_id, $main_image = false, $size = 'woocommerce_single' ) { | |
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' ); | |
$thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', array( $gallery_thumbnail['width'], $gallery_thumbnail['height'] ) ); | |
$image_size = apply_filters( 'woocommerce_gallery_image_size', $size ); | |
$full_size = apply_filters( 'woocommerce_gallery_full_size', apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' ) ); | |
$thumbnail_src = wp_get_attachment_image_src( $attachment_id, $thumbnail_size ); | |
$full_src = wp_get_attachment_image_src( $attachment_id, $full_size ); | |
$image = wp_get_attachment_image( $attachment_id, $image_size, false, array( | |
'title' => get_post_field( 'post_title', $attachment_id ), | |
'data-caption' => get_post_field( 'post_excerpt', $attachment_id ), | |
'data-src' => $full_src[0], | |
'data-large_image' => $full_src[0], | |
'data-large_image_width' => $full_src[1], | |
'data-large_image_height' => $full_src[2], | |
'class' => $main_image ? 'wp-post-image skip-lazy' : 'skip-lazy', // skip-lazy, blacklist for Jetpack's lazy load. | |
) ); | |
$image_wrapper_class = $main_image ? 'slide first' : 'slide'; | |
$image_html = $main_image ? $image : '<a href="' . esc_url( $full_src[0] ) . '">' . $image . '</a>'; | |
return '<div data-thumb="' . esc_url( $thumbnail_src[0] ) . '" class="woocommerce-product-gallery__image '.$image_wrapper_class.'">' . $image_html . '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment