-
-
Save asadaly111/c4cf9417211023697277a1ad62ad93c0 to your computer and use it in GitHub Desktop.
WooCommerce insert wrapper around thumbnail images in loop
This file contains hidden or 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
/* 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now its working fine for me as I wanted to be