Skip to content

Instantly share code, notes, and snippets.

@bkspace
Last active January 9, 2025 13:11
Show Gist options
  • Save bkspace/34f2b60e8ef077612cc9f7213e76e41e to your computer and use it in GitHub Desktop.
Save bkspace/34f2b60e8ef077612cc9f7213e76e41e to your computer and use it in GitHub Desktop.
{% liquid
assign discounts = shop.metafields.discount_kit.discount_information.value.discounts
assign current_date = 'now' | date: '%s' | times: 1
assign matched_config_ids = ""
for discount in discounts
assign config = discount.discountNode.config.value
assign starts_at = discount.startsAt | date: '%s' | times: 1
assign ends_at = discount.endsAt | date: '%s' | times: 1
if ends_at > 0 and ends_at <= current_date
continue
endif
if current_date <= starts_at
continue
endif
if config.allowB2b != true
if customer.b2b?
continue
endif
endif
if config.customerTags
assign matching_tag = false
for tag in customer.tags
for customer_tag in config.customerTags
if tag == customer_tag
assign matching_tag = true
break
endif
endfor
endfor
if matching_tag != true
continue
endif
endif
if config.marketHandles
assign matching_market = false
for market in config.marketHandles
if market == localization.market.handle
assign matching_market = true
break
endif
endfor
if matching_market != true
continue
endif
endif
if config.currencyCode
if config.currencyCode != cart.currency.iso_code
continue
endif
endif
assign matched_config_ids = matched_config_ids | append: discount.id
unless forloop.last
assign matched_config_ids = matched_config_ids | append: ","
endunless
endfor
echo matched_config_ids
%}
document.addEventListener('discount_kit:ready', (data) => {console.log(data.detail.discounts)})
{% capture matching_discount_ids %}
{% render 'match_discounts' %}
{% endcapture %}
{% assign stripped_valid_discount_ids = matching_discount_ids | strip | strip_newlines | strip_html %}
{% for id in stripped_valid_discount_ids %}
{% assign metafield_key = 'discount_' | append: id %}
{% assign discount_configuration = shop.metafields.discount_kit[metafield_key].value %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment