Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #803042

    alexdigital
    Participant

    Hi,

    I’ve noticed that the fallback image only seems to work on product pages and not category/search pages.

    http://emresolutions.com.gridhosted.co.uk/product-category/semfib/semfib-kleindiek-micromanipulators-and-nanotools/consumables/

    I have changed the fallback by adding some code to the function.php, but with or without this it makes no difference. The code i’m using is:

    add_action( ‘init’, ‘custom_fix_thumbnail’ );

    function custom_fix_thumbnail() {
    add_filter(‘woocommerce_placeholder_img_src’, ‘custom_woocommerce_placeholder_img_src’);

    function custom_woocommerce_placeholder_img_src( $src ) {
    $uploads = untrailingslashit( $upload_dir[‘baseurl’] );
    $src = $uploads . ‘http://emresolutions.com.gridhosted.co.uk/product-images/no-image.png’;

    return $src;
    }
    }

    Thanks

    #803805

    Jade
    Moderator

    Hi Alex,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #814525

    alexdigital
    Participant
    This reply has been marked as private.
    #814728

    Thai
    Moderator

    Hi There,

    Please delete your code and try with this instead:

    add_action( 'init', 'x_custom_fix_thumbnail' );
     
    function x_custom_fix_thumbnail() {
    	add_filter( 'woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src' );
    	add_filter( 'post_thumbnail_html', 'default_woo_img', 20, 2 );
    	function default_woo_img($html, $product_id){
    		$post_type = get_post_type( get_post( $product_id ) );
    		if( $post_type == "product" && !has_post_thumbnail($product_id) ){
    			$upload_dir = wp_upload_dir();
    			$uploads    = untrailingslashit( $upload_dir['baseurl'] );
    			$src        = 'http://emresolutions.com.gridhosted.co.uk/product-images/no-image.png';
    			return '<img src="'.$src.'" />';
    		} else {
    			return $html;
    		}
    	}
    	function custom_woocommerce_placeholder_img_src( $src ) {
    		$src        = 'http://emresolutions.com.gridhosted.co.uk/product-images/no-image.png';
    		return $src;
    	}
    }

    Hope it helps 🙂