• Resolved Guido

    (@guido07111975)


    Hi,

    Currently I use this snippet in my theme to add a placeholder image in case a product doesn’t have it’s own (featured) image:

    
    function wc_custom_thumbnail() { 
    	function wc_custom_placeholder_img( $src ) { 
    		$src = get_stylesheet_directory_uri().'/images/product.jpg'; 
    		return $src; 
    	}
    	add_filter('woocommerce_placeholder_img_src', 'wc_custom_placeholder_img'); 
    } 
    add_action( 'init', 'wc_custom_thumbnail' ); 
    

    But I now notice woocommerce_placeholder_img_src is deprecated in 3.0.

    The placeholder snippet on the WooCommerce site isn’t updated.

    So how can I set a placeholder now?

    Guido

Viewing 6 replies - 1 through 6 (of 6 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi Guido!

    The current hook is wc_placeholder_img_src

    Cheers!

    Thread Starter Guido

    (@guido07111975)

    Hi,

    Thanks for your response. When I replace the filter with the new one, my code snippet doesn’t work anymore; the default WC placeholder is displayed again.

    
    add_filter('wc_placeholder_img_src', 'wc_custom_placeholder_img');
    

    Guido

    I use this and it seems to work:

    
    /**
    * xxxxxx FUNCTION TO CHANGE WOOCOMMERCE PLACEHOLDER
    */
    // Add action to hook into the approp
    add_filter( 'woocommerce_placeholder_img_src', 'growdev_custom_woocommerce_placeholder', 10 );
    /**
     * Function to return new placeholder image URL.
     */
    function growdev_custom_woocommerce_placeholder( $image_url ) {
      $image_url = '/placeholderMODIFIED.png';  // change this to the URL to your custom placeholder
      return $image_url;
    }
    
    Thread Starter Guido

    (@guido07111975)

    Hi,

    It still does work but filter woocommerce_placeholder_img_src is deprecated and is replaced by wc_placeholder_img_src.

    But when I use this new filter in my code snippet, my custom placeholder isn’t displayed anymore:

    
    function wc_custom_thumbnail() { 
    	function wc_custom_placeholder_img( $src ) { 
    		$src = get_stylesheet_directory_uri().'/images/product.jpg'; 
    		return $src; 
    	}
    	add_filter('wc_placeholder_img_src', 'wc_custom_placeholder_img'); 
    } 
    add_action( 'init', 'wc_custom_thumbnail' ); 
    

    So the problem is the new filter: wc_placeholder_img_src

    Guido

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi Guido!

    Just had another look — its actually the woocommerce_placeholder_img_src function that is deprecated, the woocommerce_placeholder_img_src filter still works.

    Thread Starter Guido

    (@guido07111975)

    Aha, thanks… there was some confusion here (filter vs function) ??

    So I don’t have to update my code snippet anymore. Solved.

    Guido

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Placeholder image in WooCommerce’ is closed to new replies.