Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
      // set default product feature image
      // code goes in functions php for your child theme
      add_filter ('woocommerce_single_product_image_html', 'set_default_product_image', 10, 2);
      function set_default_product_image($html, $post_id) {
        $position = stripos($html, 'placeholder.png');
        if ($position !== false) {
          $html = '<img src="https://www.my-site-name.com/wp-content/uploads/logo.jpg" alt="Logo" class="alignnone">'; // alter to suit
        }
        return $html;
      }

    Should work on the product page but sorry doesn’t work on the archives page.

    This should work for the product archives page:

    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 '<div class="no-image"><img src="https://www.mysite.com/wp-content/uploads/logo.jpg" alt="Logo" />';
        }
      }
    
      add_action( 'woocommerce_after_shop_loop_item', 'after_imageless_product', 9 );
      function after_imageless_product() {
        if( !has_post_thumbnail( get_the_id() ) ){
          add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
          echo '</div>';
        }
      }

    For some themes you may get doubled images, if so, comment out the last add_action line.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default feature image for all products’ is closed to new replies.