Last active
March 17, 2020 09:32
-
-
Save nayemDevs/64f63e359441a9b18f02629689fe6ce3 to your computer and use it in GitHub Desktop.
Changing default thumbnail image of WooCommerce product
This file contains hidden or 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
| <?php | |
| /** | |
| * Change the placeholder image | |
| */ | |
| 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'] ); | |
| // replace with path to your image | |
| $src = $uploads . '/2020/03/default-product-image.png'; | |
| return $src; | |
| } | |
| /*For thumbnail*/ | |
| add_filter('woocommerce_placeholder_img', 'downloadclub_woocommerce_placeholder_img', 10, 3); | |
| function downloadclub_woocommerce_placeholder_img($image_html, $size, $dimensions){ | |
| $image = wc_placeholder_img_src( $size ); | |
| //replace image url | |
| $image_html = '<img src= "http://site.com/wp-content/uploads/2020/03/default-product-image-2.png"' . esc_attr( $image ) . '" alt="' . esc_attr__( 'Placeholder', 'woocommerce' ) . '" width="' . esc_attr( $dimensions['width'] ) . '" class="woocommerce-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />'; | |
| return $image_html; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment