Skip to content

Instantly share code, notes, and snippets.

@asadaly111
Forked from krogsgard/woo-loop-image-wrap.php
Created September 20, 2018 22:09
Show Gist options
  • Save asadaly111/c4cf9417211023697277a1ad62ad93c0 to your computer and use it in GitHub Desktop.
Save asadaly111/c4cf9417211023697277a1ad62ad93c0 to your computer and use it in GitHub Desktop.
WooCommerce insert wrapper around thumbnail images in loop
/* This snippet removes the action that inserts thumbnails to products in teh loop
* and re-adds the function customized with our wrapper in it.
* It applies to all archives with products.
*
* @original plugin: WooCommerce
* @author of snippet: Brian Krogsard
*/
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
/**
* WooCommerce Loop Product Thumbs
**/
if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
function woocommerce_template_loop_product_thumbnail() {
echo woocommerce_get_product_thumbnail();
}
}
/**
* WooCommerce Product Thumbnail
**/
if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
global $post, $woocommerce;
$output = '<div class="imgs">';
if ( has_post_thumbnail() ) {
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(),'full', true);
$output .= '<img src="'. $thumbnail[0] .'" >';
} else {
$output .= '<img src="'. woocommerce_placeholder_img_src() .'" >';
}
$output .= '</div> <div class="caption"><div><div>';
return $output;
}
}
@asadaly111
Copy link
Author

Now its working fine for me as I wanted to be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment