Skip to content

Instantly share code, notes, and snippets.

View ihorduchenko's full-sized avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / shopify-checkout.liquid
Created August 9, 2023 19:06
Manipulate with checkout discount area using Shopify Checkout library + js modules assets
{%- comment -%}
https://www.npmjs.com/package/@adearriba/shopify-checkout?activeTab=code
{%- endcomment -%}
<script type="module" src="{{ 'shopify-checkout.js' | asset_url }}"></script>
<script>
import { $checkout } from './shopify-checkout.js';
$checkout.on('load', (e) => {
console.log(e);
let discountNumberLineEl = document.querySelector('[data-checkout-discount-amount-target]');
@ihorduchenko
ihorduchenko / 2-fetch-calls.js
Created August 8, 2023 23:01
Handle 2 fetch API calls one by one
var post;
// Call the API
fetch('https://jsonplaceholder.typicode.com/posts/5').then(function (response) {
if (response.ok) {
return response.json();
} else {
return Promise.reject(response);
}
}).then(function (data) {
@ihorduchenko
ihorduchenko / close-dropdown-on-click-outside.html
Created August 4, 2023 20:00
Close dropdown on clicking outside
<fieldset class="filtersDropdown">
<div class="filtersDropdownTrigger">
Dropdown trigger
<div class="caret pointer-events-none">
<svg class="pointer-events-none"><use xlink:href="#icon-angle-down"></use></svg>
</div>
</div>
<div class="dropdown-body"></div>
</fieldset>
@ihorduchenko
ihorduchenko / thank-you-page-detector.liquid
Created July 18, 2023 13:09
Detect order status page (Thank you page) in Shopify checkout
{%- assign is_thank_you_page = false -%}
{%- if checkout_html_classes contains 'page--thank-you' -%}
{%- assign is_thank_you_page = true -%}
{%- endif -%}
@ihorduchenko
ihorduchenko / ablyft-helper-classes.js
Created July 13, 2023 08:18
Add helper classes by ABlyft to detect whether script has been loaded
ablyftTools.domLoaded(function(){
document.documentElement.classList.add('ablyft-loaded');
document.documentElement.classList.remove('no-ablyft');
});
@ihorduchenko
ihorduchenko / prevent-double-event-listener.js
Last active July 6, 2023 15:57
Prevent 'change' event from being triggered twice (especially on radio buttons)
el.addEventListener('change', (e) => {
e.stopImmediatePropagation();
});
@ihorduchenko
ihorduchenko / metafields-filters.liquid
Created July 3, 2023 08:19
Useful Shopify metafields filters
{{ richtext | metafield_tag }} - displays richtext metafield tag
<video>
<source
src="{{ video | file_url }}"
type="video/mp4">
</video> - displays file metafield, video in this case
@ihorduchenko
ihorduchenko / section-sample.liquid
Created June 1, 2023 21:02
How to limit section using for specific on specific templates only
{% schema %}
{
"name": "Section name",
"templates": ["product"],
"settings": [],
"presets": [
{
"category": "Text",
"name": "Section name",
"settings": {}
@ihorduchenko
ihorduchenko / main-product.liquid
Created June 1, 2023 10:06
Cookie-based discount of products before cart and checkout using shareable link (Impact theme)
{% comment %}Necessary HTML elements{% endcomment %}
{%- if settings.discount_code_topbanner != blank -%}
<div class="dCodePDPTopBanner d-none">
Dein Rabattcode <strong class="dCodeName">testAmount_20</strong> wurde aktiviert. Du sparst <strong class="dCodePercent">20</strong>% auf deinen Einkauf!
</div>
{%- endif -%}
<span class="savingsBadge"
data-raw-price="{{ variant.price }}"
data-raw-comp-price="{{ variant.compare_at_price }}">
@ihorduchenko
ihorduchenko / pdp-upsells-with-async-atc.liquid
Last active May 18, 2023 21:41
Product upsells with async Add to cart functionality
<div class="pdp-upsells--panel-row">
{%- for prod in metafield -%}
{%- assign first_variant = prod.variants[0] -%}
{%- assign visibility_class = '' -%}
<div class="pdp-upsells--cell">
<div class="pdp-upsells--item">
<div class="pdp-upsells--item-image img-contain">
{%- if prod.featured_image != blank -%}
<img
loading="lazy"