Add Product IDs to Swatch data

1 vote

Add Product IDs to Swatch data

Here’s a way that the swatches plugin could provide the product (or variation) ID as a data attribute. It would allow developers to utilize that ID and show any variation specific data they want (Title, Price, Add to Cart action, etc.) Here’s how it would be possible: In class-products.php there is a variable called $first_variation_id. This already contains the variation ID we need. In the foreach loop where the $swatch_item_html is being constructed, the variation ID could be added via the following code changes: Before: $swatch_item_html = sprintf( ‘%s’, $oos_item_class, $url, $swatch_data[‘swatch_type’], $disabled_swatch_class, $variation_image_url[‘srcset’], $variation_image_url[‘sizes’], $swatch_html ); After: $swatch_item_html = sprintf( ‘%s’, $oos_item_class, $url, $swatch_data[‘swatch_type’], $disabled_swatch_class, $variation_image_url[‘srcset’], $variation_image_url[‘sizes’], $first_variation_id, $swatch_html ); The end result is that we have the product variation ID in the data for the swatch item.
Category: Attribute Swatches Avatar cdlenfert shared this idea

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by Simple feature Requests