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 / 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"
@ihorduchenko
ihorduchenko / metaobject-hierarchical-list.liquid
Created April 22, 2023 00:27
How to fetch the value of metaobject containing the list of other metaobjects from anywhere in Shopify
{% assign entries = shop.metaobjects.pdp_buybox_advantages['pdp-buybox-advantages']['advantages'].value %}
{%- for item in entries -%}
{%- assign image = item.image.value -%}
{%- assign text = item.text.value -%}
{%- endfor -%}
@ihorduchenko
ihorduchenko / countdown-timer.html
Last active April 4, 2023 23:23
Vanilla JS countdown timer to specific date
<div class="countTimer" data-date="01 Jan 2030 00:00:00 GMT">
<div class="countdown-wrapper">
<div class="countdown-cell">
<span class="timer-number tDays">00</span>
<div class="timer-caption">Days</div>
</div>
<div class="countdown-cell">·</div>
<div class="countdown-cell">
<span class="timer-number tHours">00</span>
<div class="timer-caption">hours</div>
@ihorduchenko
ihorduchenko / shopify-focal-points.liquid
Created February 28, 2023 22:46
Shopify images focal points usage example
{%- if section.settings.main_image != blank -%}
{%- assign focal_point = section.settings.main_image.presentation.focal_point -%}
{%- capture focal_point_css -%}
{%- if focal_point != blank -%}
style="object-position:{{ focal_point.x }}% {{ focal_point.y }}%;"
{%- endif -%}
{%- endcapture -%}
<div class="collection-banner--img img-cover">
<img class="lazyload" data-src="{{ section.settings.main_image | img_url: 'master' }}" alt="Banner" {{ focal_point_css }}>
</div>
@ihorduchenko
ihorduchenko / get-cart.liquid
Created February 16, 2023 12:48
Programmatically get cart object in Shopify
<script>
const cartRoute = '{{ routes.cart_url | append: '.js' }}';
function forceCartUpdate() {
var getCartForce = function() {
var url = ''.concat(cartRoute, '?t=').concat(Date.now());
return fetch(url, {
credentials: 'same-origin',
method: 'GET'
}).then(response => response.json());
@ihorduchenko
ihorduchenko / cart-total-based-free-gifts.rb
Created January 25, 2023 16:17
Shopify Scripts: Offer free products as gifts when specific cart total reached (with multiple thresholds)
# ================================ Customizable Settings ================================
# ================================================================
# Spend $X, get Product Y for Z Discount
#
# If the cart total is greater than (or equal to) the entered
# threshold (less the discounted amount), the entered number of
# matching items is discounted by the entered amount.
#
# - 'product_selector_match_type' determines whether we look for
# products that do or don't match the entered selectors. Can
@ihorduchenko
ihorduchenko / grid-auto-placement.html
Last active January 17, 2023 12:26
Force certain column to change it's position on desktop outside of the flow
<!-- https://prnt.sc/f05LCS_YIdZq -->
<div class="product-hero">
<div class="product-media__wrapper">
Product media
</div>
<div class="product__info">
Product info
</div>
@ihorduchenko
ihorduchenko / input-radio-change-trigger.js
Created November 16, 2022 23:22
Trigger radio-button change event
if ('createEvent' in document) {
var evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true);
inputRadioDOMelement.dispatchEvent(evt);
}
@ihorduchenko
ihorduchenko / shopifyCartAjaxify.js
Created November 10, 2022 15:10
Ajax methods to manage cart items in Shopify
// Add item to the cart
function cartItemAdd(id, qty) {
fetch('/cart/add.js', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({'items': [{'id':id,'quantity':qty}]})