Skip to content

Instantly share code, notes, and snippets.

@hugosolar
Created November 30, 2018 01:50
Show Gist options
  • Save hugosolar/dd5064d3a1de065bf4d0a449a42c0eea to your computer and use it in GitHub Desktop.
Save hugosolar/dd5064d3a1de065bf4d0a449a42c0eea to your computer and use it in GitHub Desktop.
Use category image instead custom placeholder on Woocommerce
/**
* 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