Support » Plugin: Variation Swatches for WooCommerce » Images on checkout page

Viewing 1 replies (of 1 total)
  • permanyer

    (@permanyer)

    I have the same problem. This is what i have come up to:

    Show Image Swatch in Cart, overriding the cart product name:

    function woocommerce_cart_item_name_filter( $link_text, $product_data ) {
       
        $product = $product_data['data'];
        $html = '';
    
        if('variation' == $product->get_type()){
            $html .= '<div class="title-width-variations">';
        }
    
        $html .= '<div class="entry-text single-product-title in-cart-filter">';
        $html .= '<span class="entry-name">'.$product->get_title().'</span>';
        $html .= '<br>';
        $html .= '<span class="entry-sku">'.$product->get_sku().'</span>';
        $html .= '</div>';
    
        if('variation' == $product->get_type()){
            
            $variations = $product_data['variation'];
    
            foreach ($variations as $variation_key => $variation_value) {
    
                switch ($variation_key) {
                    case 'attribute_pa_color':
                        $term = get_term_by('slug', $variation_value, 'pa_color');
                        $image_id = get_term_meta( $term->term_id, 'image', true );
                        $image = wp_get_attachment_url( $image_id );
    
                        $html .= '<div class="variation '.$variation_key.'"><img src="'.$image.'"></div>';
                        
                        break;
                    
                    case 'attribute_pa_talla':
                    default:
    
                        $html .= '<div class="variation uppercase'.$variation_key.'">'.$variation_value.'</div>';
                    
                        break;
                }
                
            }
    
            $html .= '</div>';
        }
       
        return $html;
    }
    /* Filter to override cart_item_name */
    add_filter( 'woocommerce_cart_item_name', 'woocommerce_cart_item_name_filter', 10, 2 );
    
    • This reply was modified 2 years ago by permanyer.
    • This reply was modified 2 years ago by permanyer.
Viewing 1 replies (of 1 total)
  • The topic ‘Images on checkout page’ is closed to new replies.