• Resolved kreativamarketing

    (@kreativamarketing)


    So, here is the woocommerce setting that I have.

    I have a few categores, let’s call them A, B, C, D, E… and so on.

    From the backend, I gave category images to each categories.

    Now, let’s say I post a product in the category A without selecting any images.

    The product just shows the woocommerce default image (the one with the grey background).

    Is there a way to use the category images as the default product image when there is no image selected?

    I have tried a few codes, this is the last one I have:

    add_action( 'init', 'custom_fix_thumbnail');
    
    function custom_fix_thumbnail(){
    
    	add_filter('wc_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
    
    	function custom_woocommerce_placeholder_img_src( $src ) {
    		if (is_shop() || is_singular('product') || is_archive() || is_checkout() || is_cart()) {
    			global $post;
                $array = get_the_terms($post->ID, 'product_cat');
                reset($array);
                $first_key = key($array);
                $thumbnail_id = get_woocommerce_term_meta($first_key, 'thumbnail_id', true);
    
                // get the image URL for parent category
                $image = wp_get_attachment_url($thumbnail_id);
    
                // print the IMG HTML for parent category
                if ($image)
                    $src = $image;
    
    		}
    		return $src;
    	}
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter kreativamarketing

    (@kreativamarketing)

    Thanks, I will try on those groups as well and wait if anyone answers here.

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    No one was able to chime in to help, so I’m going to wrap up this thread now. I can strongly recommend the tips that RK left above to help you further.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce change default product images to their category image’ is closed to new replies.