Created
May 8, 2013 15:54
-
-
Save woogist/5541418 to your computer and use it in GitHub Desktop.
WooCommerce - Change Placeholder 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
/* | |
* 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; | |
} | |
} |
This is such a junk example and could confuse newbie devs. Seriously, wrapping a filter registration to fire on the init action?
@ChrisChiera That's the function that's depreciated, the filter is still correct.
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
and if i want insert a random image of the products automaticaly?