Skip to content

Instantly share code, notes, and snippets.

@woogist
Created May 8, 2013 15:54
Show Gist options
  • Save woogist/5541418 to your computer and use it in GitHub Desktop.
Save woogist/5541418 to your computer and use it in GitHub Desktop.
WooCommerce - Change Placeholder Image
/*
* goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)
*
**/
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/2012/07/thumb1.jpg';
return $src;
}
}
@TechRemarker
Copy link

TechRemarker commented Jan 22, 2017

This is listed on the official WooCommerce documents but WooCommerce also says it's depreciated: https://docs.woocommerce.com/wc-apidocs/function-woocommerce_placeholder_img_src.html.

The depreciated woocommerce_placeholder_img_src should be replaced with wc_placeholder_img_src

*https://docs.woocommerce.com/wc-apidocs/function-wc_placeholder_img_src.html

@ilgrizly
Copy link

ilgrizly commented May 2, 2017

and if i want insert a random image of the products automaticaly?

@ajdinmore
Copy link

ajdinmore commented Aug 8, 2017

This is such a junk example and could confuse newbie devs. Seriously, wrapping a filter registration to fire on the init action?

@ajdinmore
Copy link

@ChrisChiera That's the function that's depreciated, the filter is still correct.

@braddalton
Copy link

braddalton commented Sep 8, 2018

This is what is in woocommerce > includes > wc-product-functions.php around line 282

function wc_placeholder_img_src() {
	return apply_filters( 'woocommerce_placeholder_img_src', WC()->plugin_url() . '/assets/images/placeholder.png' );
}

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