Created
November 30, 2018 01:50
-
-
Save hugosolar/dd5064d3a1de065bf4d0a449a42c0eea to your computer and use it in GitHub Desktop.
Use category image instead custom placeholder on 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
/** | |
* Change the placeholder image | |
*/ | |
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src'); | |
function custom_woocommerce_placeholder_img_src($src) | |
{ | |
global $post; | |
$terms = wp_get_post_terms($post->ID, 'product_cat'); | |
$thumbnail_id = get_woocommerce_term_meta($terms[0]->term_id, 'thumbnail_id', true); | |
if (!empty($thumbnail_id)) { | |
$image = wp_get_attachment_image_src( $thumbnail_id, 'thumb' ); | |
$src = $image[0]; | |
} | |
return $src; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment