Skip to content

Instantly share code, notes, and snippets.

@makfruit
Last active December 15, 2015 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makfruit/5302479 to your computer and use it in GitHub Desktop.
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
<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>
@ian-holden
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment