Created
July 11, 2016 19:40
-
-
Save arshidkv12/cea8d9dc370844ce9ed4782e6deafbdf to your computer and use it in GitHub Desktop.
Make thumbnails replace the main image instead of opening fancybox [wooCommerce]
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 | |
/** | |
* Plugin Name: nice_woocommerce_gallery | |
* | |
*/ | |
add_action('wp_footer','nice_woocommerce_gallery'); | |
function nice_woocommerce_gallery() { | |
?> | |
<script> | |
jQuery(document).ready(function($){ | |
$(document).on('click','.thumbnails a',function(e){ | |
e.preventDefault(); | |
var img_url = $(this).attr('href'); | |
var img_src = $(this).find('img').attr('srcset'); | |
$('.woocommerce-main-image').find('img').attr('src',img_url); | |
$('.woocommerce-main-image').find('img').attr('srcset',img_src); | |
$('.woocommerce-main-image').closest('a').attr('href',img_url); | |
$("a.zoom").prettyPhoto({ | |
hook: 'data-rel', | |
social_tools: false, | |
theme: 'pp_woocommerce', | |
horizontal_padding: 20, | |
opacity: 0.8, | |
deeplinking: false | |
}); | |
$("a[data-rel^='prettyPhoto']").prettyPhoto({ | |
hook: 'data-rel', | |
social_tools: false, | |
theme: 'pp_woocommerce', | |
horizontal_padding: 20, | |
opacity: 0.8, | |
deeplinking: false | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
if(!function_exists('woocommerce_show_product_thumbnails')) { | |
function woocommerce_show_product_thumbnails() { | |
global $post, $product, $woocommerce; | |
$attachment_ids = $product->get_gallery_attachment_ids(); | |
if ( $attachment_ids ) { | |
$loop = 0; | |
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 ); | |
?> | |
<div class="thumbnails <?php echo 'columns-' . $columns; ?>"><?php | |
foreach ( $attachment_ids as $attachment_id ) { | |
$classes = array( 'thumbnail' ); | |
if ( $loop === 0 || $loop % $columns === 0 ) | |
$classes[] = 'first'; | |
if ( ( $loop + 1 ) % $columns === 0 ) | |
$classes[] = 'last'; | |
$image_link = wp_get_attachment_url( $attachment_id ); | |
if ( ! $image_link ) | |
continue; | |
$image_title = esc_attr( get_the_title( $attachment_id ) ); | |
$image_caption = esc_attr( get_post_field( 'post_excerpt', $attachment_id ) ); | |
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), 0, $attr = array( | |
'title' => $image_title, | |
'alt' => $image_title | |
) ); | |
$image_class = esc_attr( implode( ' ', $classes ) ); | |
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<a href="%s" class="%s" title="%s" >%s</a>', $image_link, $image_class, $image_caption, $image ), $attachment_id, $post->ID, $image_class ); | |
$loop++; | |
} | |
?></div> | |
<?php | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment