[tc_product id="{{product_id}}"]
document.addEventListener('DOMContentLoaded', function() { // Array of your attribute names var attributes = ['pa_diameter', 'pa_base-curve']; attributes.forEach(function(attrName) { // Use attribute selector to avoid issues with special characters var select = document.querySelector('select[name="' + attrName + '"]'); if (select) { // Get options that actually have a value var options = Array.from(select.options).filter(function(opt) { return opt.value !== ''; }); if (options.length === 1) { select.value = options[0].value; // Trigger change event in case WooCommerce or other scripts need it var event = new Event('change', { bubbles: true }); select.dispatchEvent(event); } } }); });