Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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>
@makfruit

This comment has been minimized.

Copy link
Owner Author

@makfruit makfruit commented Jul 11, 2013

Demo: http://jsfiddle.net/makfruit/n3Kxh/ (Select the 'Apple*' product in the Fruit categroty)

@ian-holden

This comment has been minimized.

Copy link

@ian-holden ian-holden commented Feb 2, 2014

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