Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // code goes in functions php for your child theme
- // set default product image on product page
- add_filter ('woocommerce_placeholder_img_src', 'my_placeholder');
- function my_placeholder($src) {
- return get_site_url().'/wp-content/uploads/logo.jpg'; // enter your default image
- }
- // set default product image on archive page
- // edit classes to suit your theme if necessary
- // credit: Theme Fusion Community Forum mainly
- add_action( 'woocommerce_before_shop_loop_item', 'before_imageless_product', 9 );
- function before_imageless_product() {
- if( !has_post_thumbnail( get_the_id() ) ){
- remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
- echo '<a href="'.get_permalink(get_the_id()).'" class="product_item_link product_image_link">';
- echo '<div class="no-image"><img src="'.get_site_url().'/wp-content/uploads/logo.jpg" />';
- echo '</a>';
- }
- }
- add_action( 'woocommerce_after_shop_loop_item', 'after_imageless_product', 9 );
- function after_imageless_product() {
- if( !has_post_thumbnail( get_the_id() ) ){
- // next line is needed for 2015 theme, maybe others, but comment out if doubled images appear
- // add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
- echo '</div>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement