fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

Show selected attribute variation name beside the title – not working on my theme

Adam Jóźwiak

Hi,

I love your plugin, it is the best one of which I tested for variations swatches.

I have an issue with shwoing selected attribute variation name beside the title. It is simply not working on my theme, there is nothing shown beside the title, not the attribute nor variation label separator. It is an Uncode theme and they officialy recommend your plugin. Can you help me with that?

Best regards,

Adam

Hakik Zaman

Hi Adam,

Thanks for reaching out to us. Can you please contact the theme author regarding this? We have tested it with all the basic themes and it is working well. So, I have inspected it deeply and found some custom code regarding the Variation Swatches. They have customized some of our scripts inside their theme.

I hope they can give you the right direction regarding this matter.

Also, let us know the fix.

Thank You

Adam Jóźwiak

Hi Hakik,

Thank you for your quick reply.

I have contacted them but got a reply that plugin compatibilities are completely normal and they won’t do anything about it.

Is there any chance I can try to repair it with a custom code? Can you target which file/code/function is responsible for this feature?

Best regards,

Adam

Adam Jóźwiak

Hi,

I have managed to resolve it with this JS code:

jQuery(document).ready(function($) {
// Hook into the variation select events
$(‘.variations select’).change(function() {
var selectedOption = $(this).find(‘:selected’);
var attributeTitle = selectedOption.text();

// Find the label container within the current attribute row
var labelContainer = selectedOption.closest(‘.label’);
var label = labelContainer.find(‘label’);

// Update the label content without quotes around the selected value
// Check if the selected option is “Choose an option” and update label accordingly
if (attributeTitle === ‘Choose an option’) {
var labelText = label.text().split(‘:’)[0] + ‘: ‘;
label.text(labelText); // Restore the default text
} else {
var labelText = label.text().split(‘:’)[0] + ‘: ‘ + attributeTitle;
label.text(labelText);
}
});

// Update the variation labels on page load
$(‘.variations select’).each(function() {
var selectedOption = $(this).find(‘:selected’);
var attributeTitle = selectedOption.text();

// Find the label container within the current attribute row
var labelContainer = selectedOption.closest(‘.label’);
var label = labelContainer.find(‘label’);

// Update the label content without quotes around the selected value
if (attributeTitle === ‘Choose an option’) {
var labelText = label.text().split(‘:’)[0] + ‘: ‘;
label.text(labelText); // Set the label to empty
} else {
var labelText = label.text().split(‘:’)[0] + ‘: ‘ + attributeTitle;
label.text(labelText);
}
});
});

Hakik Zaman

Hi Adam,

Sorry for my late response. We have been on our weekend leave since Thursday.

I am very glad that you have found the solution to this issue.

Did you add it using a plugin or edit the theme/plugin file?

Thanks in advance for your cooperation.