• Resolved volcomjon

    (@volcomjon)


    my catalog comprises of all variable products, each with multiple variations.

    I have the default form value set for each product to be a specific variation.

    all variations have an image assigned

    the problem:

    on category / shop pages, these products show the woocommerce placeholder image instead of the default variation image. If I set a “featured image” for the product, this is shown in the loop of products. removing it simply reverts to the placeholder despite a default variant being selected.

    I have disabled all plugins (except woo) and reverted to a default wp theme – the placeholder still shows with no change.

    how can you get the default selected variation image to show in category pages??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter volcomjon

    (@volcomjon)

    anyone?

    Thread Starter volcomjon

    (@volcomjon)

    I’ve cobbled a function together to achieve this, but I honestly cant believe this is required? am I missing something really obvious in woocommerce?

    remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
    function own_woocommerce_thumbnail() {
      global $product;
    
      // HERE your targeted product attribute taxonomy
      $taxonomy = 'pa_model-colour';
    
      if( $product->is_type('variable') ){
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $variation )
        {
            $isDefVariation=false;
            foreach($product->get_default_attributes() as $key=>$val){
                if($variation['attributes']['attribute_'.$key]==$val){
                    $isDefVariation=true;
                }
            }
            if($isDefVariation){
                $image = $variation['image']['thumb_src'];
            }
        }
        echo '<img src="' . $image .'" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail">';
      }
    
    }
    add_action('woocommerce_before_shop_loop_item_title', 'own_woocommerce_thumbnail', 10);
    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @volcomjon. I know it’s been a while since you asked this question, but I hope my answer is useful.

    The default image used for a variable product is the product image that you’ve assigned to the product, not the image from the default variation:

    If you want the image from the default variation to automatically be used as the product image, then that requires customization, as you’ve done.

    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @volcomjon. We haven’t heard back from you so I’m going to go ahead and mark this thread as resolved. If you still need help with this issue or have any other questions about the WooCommerce plugin, please start a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Default Variation Image not showing on category / shop page’ is closed to new replies.