Last active
December 15, 2015 18:19
-
-
Save makfruit/5302479 to your computer and use it in GitHub Desktop.
An HTML/Javascript code snippet for Ecwid to show/hide product options depending on a trigger(expander) option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
/* An HTML/Javascript code snippet for Ecwid to show/hide product options depending on a trigger(expander) option */ | |
if (typeof(Ecwid) == 'object') { | |
Ecwid.OnAPILoaded.add(function() { | |
var expanderOptionName = "Do_you_want_extra_options"; | |
var expanderOptionFlagValue = "Yes"; | |
function checkExpandableOptions() { | |
// Detect the current selection of the 'expander' option | |
var expanderOptionCurrentValue = jQuery("div[class *= ecwid-productoption-" + expanderOptionName + "] input:checked + label > span").text(); | |
// Show or hide product options depending on the 'expander' option value | |
if (expanderOptionCurrentValue == expanderOptionFlagValue) { | |
// Show all options | |
jQuery('div.ecwid-productBrowser-details-optionPanel').show(); | |
} else { | |
// Hide all options | |
jQuery('div.ecwid-productBrowser-details-optionPanel').hide(); | |
// Show expander option | |
jQuery("div[class *= ecwid-productoption-" + expanderOptionName + "]").show(); | |
} | |
} | |
Ecwid.OnPageLoaded.add(function(page) { | |
if ('PRODUCT' == page.type) { | |
checkExpandableOptions(); | |
// Attach a handler to the 'expander' option | |
jQuery("div[class *= ecwid-productoption-" + expanderOptionName + "] input[type=radio]").click(function() { | |
checkExpandableOptions(); | |
}); | |
} | |
}); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for this example script. can you suggest a way to get it working with the "change" options pop-up from the cart page?