1
Show one variation in loop layout (like all the colours available)

Sometimes it is interesting to show in the shop (in the loop) all the colors available (one of the attributes).

The idea is to show all the colors available or all the sizes, as a teaser, not to shop or put the products in the cart.

Join the conversion, Login to Reply


user-img gerwin - 18 July 2024

Not sure if you have coding knowledge. But something like this should work in the basis. You can add the shortcode to your loop layout in Divi:

Add to functions.php

// Add shortcode to display product variations in loop layout
function display_product_variations( $atts ) {
    global $product;
    $output = '';
    // Check if product has variations
    if ( $product->is_type( 'variable' ) ) {
        // Get available variations
        $variations = $product->get_available_variations();
        // Loop through variations and display each color attribute
        foreach ( $variations as $variation ) {
            $output .= '<span class="product-variation">';
            $output .= $variation['attributes']['attribute_pa_color'];
            $output .= '</span>';
        }
    }
    return $output;
}
add_shortcode( 'display_variations', 'display_product_variations' );

[display_variations]

Upvoters
1
Feature Details

Status: In Review

Board: Divi BodyCommerce

Created: 18 July 2024

Last Updated: 18 July 2024

Posted By: eric

© 2024 Divi Engine