daily pastebin goal
32%
SHARE
TWEET

WooCommerce - Set default product images

lorro Jun 10th, 2015 (edited) 223 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // code goes in functions php for your child theme
  3.  
  4.   // set default product image on product page
  5.   add_filter ('woocommerce_placeholder_img_src', 'my_placeholder');
  6.   function my_placeholder($src) {
  7.     return get_site_url().'/wp-content/uploads/logo.jpg'; // enter your default image
  8.   }
  9.  
  10.   // set default product image on archive page
  11.   // edit classes to suit your theme if necessary
  12.   // credit: Theme Fusion Community Forum mainly
  13.   add_action( 'woocommerce_before_shop_loop_item', 'before_imageless_product', 9 );
  14.   function before_imageless_product() {
  15.     if( !has_post_thumbnail( get_the_id() ) ){
  16.       remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  17.       echo '<a href="'.get_permalink(get_the_id()).'" class="product_item_link product_image_link">';
  18.       echo '<div class="no-image"><img src="'.get_site_url().'/wp-content/uploads/logo.jpg" />';
  19.       echo '</a>';
  20.     }
  21.   }
  22.   add_action( 'woocommerce_after_shop_loop_item', 'after_imageless_product', 9 );
  23.   function after_imageless_product() {
  24.     if( !has_post_thumbnail( get_the_id() ) ){
  25.       // next line is needed for 2015 theme, maybe others, but comment out if doubled images appear
  26.       // add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  27.       echo '</div>';
  28.     }
  29.   }
RAW Paste Data
Top