Hello Magento Friends,

In this current Magento 2 blog, I will explain How to Change Configurable Product Description Dynamically Based on Swatches.

In Magento 2, configurable products are single products with variations in color selection, sizes, etc. You can Create Configurable Product using one of the two ways:

By default, the product description remains the same for all swatches in configurable products. We can change product descriptions based on configurable product’s swatches selection. Displaying dynamic and optimized product descriptions will help enhance the customer shopping experience with your store and aid in Google rankings.

Let’s learn How to Change Configurable Product Description Dynamically Based on Swatches in Magento 2.

Steps to Change Configurable Product Description Dynamically Based on Swatches in Magento 2:

Step 1: Create a di.xml file in the given path

{{magento_root}}/app/code/Vendor/Extension/etc/frontend/.di.xml

And then add the below code

Step 2: Create plugin file ConfigurablePlugin.php at the following path

{{magento_root}}/app/code/Vendor/Extension/Plugin/ConfigurableProduct/Product/Type/ConfigurablePlugin.php

Now add the below-mentioned code

Step 3: Now, create a plugin file ConfigurablePlugin.php at the given path

{{magento_root}}/app/code/Vendor/Extension/Plugin/ConfigurableProduct/Product/View/Type/ConfigurablePlugin.php

And include the below piece of code

Step 4: After that, create requirejs-config.js file at the below file path

{{magento_root}}/app/code/Vendor/Extension/view/frontend/requirejs-config.js

Now add the following code fragment

Step 5: Now create swatch-renderer.js file at the below path

{{magento_root}}/app/code/Vendor/Extension/view/frontend/web/js/swatch-renderer.js

Now add the following code snippet

In the swatch-renderer.js file, the custom code will get a description of the child product based on selection.

Conclusion:

This way, you can show dynamic product descriptions on the basis of configurable product swatch selection in Magento 2. If you face any hardship in displaying the product description dynamically for configurable products, let me know through the comment box.

Share the tutorial with your friends and stay updated for more. 

Happy Coding!

 

Click to rate this post!
[Total: 7 Average: 2.9]