Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #21832

    I’ve noticed that if you don’t add a featured image product thumbs don’t show. Is it possible to have it show the place holder as a default image when there is no featured image?

    #113249

    Hi BimCreate,

    You can try something like:

    /*
    * goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)
    *
    **/
    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;
    }

    And replace the /2012/07/thumb1.jpg with your own image location.

    Regards,

    Devin

    #113250

    Where do I add this code?

    #113251

    It would go into the functions.php file. You can just place it at the bottom of the file after the SEO function. Make sure to modify it for your specific image otherwise it will not work.

    Regards,

    Devin

    #113252

    Didn’t work.

    /*

    * goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)

    *

    **/

    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 );

    $src = $uploads . ‘http://www.simplextrading.net/wp-content/uploads/2013/04/coming_soon_product.png’;

    return $src;

    }

    #113253

    You’re already using an absolute path – in this case you need to change the code to:

    add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
    function custom_woocommerce_placeholder_img_src( $src ) {
    $src = 'http://www.simplextrading.net/wp-content/uploads/2013/04/coming_soon_product.png';
    return $src;
    }

    or you change it to a relative path like:

    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 . '/2013/04/coming_soon_product.png';
    return $src;
    }

    #113254

    That works for the single product page.

    Is it possible to have it on the other pages where products are shown? like the product categories and related products etc. Anywhere products are shown.

    #113255

    No, afaik not. You can try to hack the wp-contentpluginswoocommercewoocommerce-template.php file though – search for:

    if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {

    /**
    * Get the product thumbnail for the loop.
    *
    * @access public
    * @subpackage Loop
    * @return void
    */
    function woocommerce_template_loop_product_thumbnail() {
    echo woocommerce_get_product_thumbnail();
    }
    }

    and replace it with:

    if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {

    /**
    * Get the product thumbnail for the loop.
    *
    * @access public
    * @subpackage Loop
    * @return void
    */
    function woocommerce_template_loop_product_thumbnail() {
    $image = woocommerce_get_product_thumbnail();

    if(empty($image)) woocommerce_placeholder_img( 'shop_catalog' );

    echo $image;
    }
    }

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘product stock photo in each product category’ is closed to new replies.