vendredi 17 avril 2015

woocommerece change background image based on select option value in variable product page

Wordpress Plugin: woocommerece Page:Product page(variation) Aim: To change background image based on option value(eg.. blue,green) i'm trying to set a background image based on user selected variation(eg. color) for example product page display image-1.jpg as bg image if user select color blue the bg image change to image-blue.jpg


code ` $("#pictype").change(function(){ var optionvalue = $(this).val(); alert(optionvalue); if(optionvalue == 'blue' ) {

$("body").css("background-image", "url(http://ift.tt/1yAhHuK)");

} else { $("body").css("background-image", "url(http://ift.tt/1IkNvDH)"); }



});


` above code working perfectly for normal pages but variation product page get variation value as json object. I don't have any idea about json, show way to complete in dynamic or in static way


Aucun commentaire:

Enregistrer un commentaire