Add this to functions.php to set titles on variation change
// Save the titles for the variations in an object
var titles = new Object();
titles[‘0’] = ‘get_title(); ?>’;
get_available_variations();
foreach ($variations as $key => $variation) { ?>
titles[“”] = ”;
jQuery(document).ready(function($) {
// If we start with a variation in the address bar set the title
if ($(‘input.variation_id’).val() > 0) {
$(‘.product_title.entry-title’).html(titles[$(‘input.variation_id’).val()]);
}
$(‘input.variation_id’).change(function() {
// Change the title on variable product when variation changes
var var_id = $(‘input.variation_id’).val();
if (” != var_id) {
$(‘.product_title.entry-title’).html(titles[var_id]);
}
});
6 Comments
Add this to functions.php to set titles on variation change
// Save the titles for the variations in an object
var titles = new Object();
titles[‘0’] = ‘get_title(); ?>’;
get_available_variations();
foreach ($variations as $key => $variation) { ?>
titles[“”] = ”;
jQuery(document).ready(function($) {
// If we start with a variation in the address bar set the title
if ($(‘input.variation_id’).val() > 0) {
$(‘.product_title.entry-title’).html(titles[$(‘input.variation_id’).val()]);
}
$(‘input.variation_id’).change(function() {
// Change the title on variable product when variation changes
var var_id = $(‘input.variation_id’).val();
if (” != var_id) {
$(‘.product_title.entry-title’).html(titles[var_id]);
}
});
$(“.variations_form”).on(“reset_data”, function() {
$(‘.product_title.entry-title’).html(titles[‘0’]);
});
});
<?PHP
}
It messed up my post. Let me try again
It keeps messing up my code. Please find the code here to do this.
https://pastebin.com/WMnc4Ch4
Hi.
Could you put the code back on pastebin… so we can try.
Thanks
hi I tried but I get this code syntax error, unexpected ‘var’ (T_VAR), expecting end of file.
I’m interested in this feature
Hi. We would like to request this type of feature also.
It would be very helpful.
Thanks
Frank