Skip to content

Instantly share code, notes, and snippets.

@Jedtek
Created February 28, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jedtek/6ee7b2e557d498be2bee542a1c186ff8 to your computer and use it in GitHub Desktop.
Save Jedtek/6ee7b2e557d498be2bee542a1c186ff8 to your computer and use it in GitHub Desktop.
inside template {{#items}} loop I do this:
<div class="grid--full display-table">
<div class="grid__item">
{{{retNextDiscount itemQty properties }}}
</div>
</div>
helper in Custom Javascript is this:
Handlebars.registerHelper('retNextDiscount', function (qty, properties) {
if(typeof properties.subscription_id === 'string') {
return '';
}
qty = Number(Handlebars.escapeExpression(qty));
if(qty === 1) {
return '<small class="ucdcart-item__discount">5% off when buying 2</small><br>';
} else if (qty === 2) {
return '<small class="ucdcart-item__discount">10% off when buying 3 or more</small><br>';
} else if (qty >= 3) {
return '<small class="ucdcart-item__discount">You\'re getting our best discount! (10%)</small><br>';
}
});
I want to add SKU argument to function, so I can process discount text with SKU of variant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment