We love shopping when choosing product options becomes much easier like color and size option. Swatches provide an alternate way to display the selection of options just by clicking for configurable products rather than choosing an option from typical drop-down options. Also, a few days back we have written a blog on “How to use Configurable Swatches in our Custom Magento Theme” where w, these swatches are only available for the default package. But we provide code through which you can add this feature in your custom theme.
But there is one problem when you create swatches from the product Magento creates global swatches for all the products that create a bad impression on your customers as shown below.

So, we are back with a small piece of code that allows you to set product-wise swatches in your Magento 2 store.
First create “Di.xml” file inside etc folder using below code.
app\code\Vendor\Extension\etc

Now Create New Block file name Configswatch.php At this path and add below code to that file.
app\code\Vendor\Extension\Block\Product

That’s it for today, Let us know if you are facing an issue while implementing swatches using this code by commenting below.
Happy Swatches!

[Total: 4   Average: 5/5]