Add attribute name to configurable select option in Magento2?

Open the file

magento/vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js

and find this line

element.options[0].innerHTML = this.options.spConfig.chooseText

repleace the line with below code

var attribute_lable = this.options.spConfig.attributes[element.id.replace(/[a-z]*/, '')]['label'];
element.options[0].innerHTML = this.options.spConfig.chooseText + attribute_lable;

On page load change dropdown label,
Open the file

vendor\magento\module-configurable-product\view\frontend\templates\product\view\type\options\configurable.phtml

and find the line

<option value=""><?= /* @escapeNotVerified */ __('Choose an Option...') ?></option>

repleace the line with below code

<?php 
$attrlabel = array();(Declared before loop)
$attrlabel[$i] = $_attribute->getProductAttribute()->getStoreLabel();?>
<option value=""><?phpecho 'Choose '.$attrlabel[$i];?></option>

Leave a Reply

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