Created
July 28, 2019 07:43
-
-
Save manchumahara/5f8c13e30294f571718f8faed3735ec3 to your computer and use it in GitHub Desktop.
Filter 'woocommerce_product_get_image' to custom image
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
add_filter('woocommerce_product_get_image', 'downloadclub_woocommerce_product_get_image', 10, 6); | |
function downloadclub_woocommerce_product_get_image($image, $wc_product_obj, $size, $attr, $placeholder, $image2){ | |
if ( $wc_product_obj->get_image_id() ) { | |
$product_id = $wc_product_obj->get_id(); | |
$content_url = content_url(); | |
$thumb_url = ''; | |
if ( file_exists( WP_CONTENT_DIR . '/uploads/productshots/' . $product_id . '-profile.png' ) ) { | |
$thumb_url = $content_url . '/uploads/productshots/' . $product_id . '-profile.png'; | |
} | |
else if ( file_exists( WP_CONTENT_DIR . '/uploads/productshots/' . $product_id . '-profile.jpg' ) ) { | |
$thumb_url = $content_url . '/uploads/productshots/' . $product_id . '-profile.jpg'; | |
} | |
if($thumb_url != ''){ | |
$image = '<img src="'.esc_url($thumb_url).'" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" alt="" />'; | |
} | |
} | |
return $image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment