Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / geo.txt
Created Jan 12, 2022
Geolocation detection endpoint
View geo.txt
https://get.geojs.io/v1/ip/geo.json
@ihorduchenko
ihorduchenko / custom-liquid.liquid
Created Dec 29, 2021
Shopify sections - "liquid" section type
View custom-liquid.liquid
{%- if section.settings.boxed -%}
<div class="grid-container contained">
{%- endif -%}
{{ section.settings.liquid }}
{%- if section.settings.boxed -%}
</div>
{%- endif -%}
@ihorduchenko
ihorduchenko / woocommerce>checkout>review-order.php
Created Dec 23, 2021
Woocommerce estimated shipping date, based on stock and shipping method
View woocommerce>checkout>review-order.php
<table class="shop_table mb-4">
<tfoot>
<!-- Skipped top part -->
<!-- Stock part -->
<?php $stock_values = array(); ?>
<?php $max_stock_period = 0; ?>
<?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { ?>
<?php $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); ?>
<?php $stock_status = $_product->get_stock_status(); ?>
@ihorduchenko
ihorduchenko / firstVisitCookies.js
Created Dec 13, 2021
Get and set cookies on first user visit
View firstVisitCookies.js
function setCookie(name, value, days) {
var expires = '';
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + (value || '') + expires + '; path=/';
}
@ihorduchenko
ihorduchenko / strict-content-using-license-key.liquid
Created Dec 1, 2021
Strict page content based on license key, stored in Google Sheets
View strict-content-using-license-key.liquid
<script defer="defer">
// Format of table is here: http://prntscr.com/219q3nl
const myDomain = window.location.hostname;
const myLicenseKey = '{{ settings.license_key | strip }}';
fetch('https://sheets.googleapis.com/v4/spreadsheets/1JO15y71ImOijJ4rcdMV7avZT5Y5lILkZin6emwg35D0/values/Keys!A2:B10000?key=AIzaSyBxbARr6-hAqdtZXXqSqDPmzap7EULYaFg')
.then(response => response.text())
.then(data => {
let resp = JSON.parse(data);
let respKeys = resp.values;
let allKeys = [];
@ihorduchenko
ihorduchenko / defer-css.html
Created Nov 26, 2021
Defer loading CSS file using media attribute trick
View defer-css.html
<link rel="stylesheet" href="theme.css" media="print" onload="this.media='all'">
View custom-checkbox.liquid
<label for="custom-checkbox" class="custom-checkbox">
<input id="custom-checkbox" type="checkbox" name="custom_checkbox">
<span>Custom checkbox</span>
</label>
<style>
.custom-checkbox > input[type=checkbox] {
opacity: 0;
cursor: pointer;
position: absolute;
View vanilla-js-tabs.liquid
<nav class="drawer-tabs--nav tabsNav" data-control=".mobileMenu">
{%- assign indexNav = 0 -%}
{%- for block in section.blocks -%}
{%- if block.type == 'menu-tab' -%}
{%- assign name = block.settings.name -%}
{%- assign name_handle = name | handleize -%}
<a href="#{{ name_handle }}" class="navv-tab tabsNavLink{% if indexNav == 0 %} is-active{% endif %}">
{{ name }}
</a>
{%- assign indexNav = indexNav | plus: 1 -%}
@ihorduchenko
ihorduchenko / mutation-observer.js
Created Aug 26, 2021
Use mutation observer to detect dynamic element creation
View mutation-observer.js
var target = document.querySelector('#bc-sf-filter-products');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
// Do some stuff
productsGrid();
}
});
});
var config = { attributes: true, childList: true, characterData: true }
@ihorduchenko
ihorduchenko / IntersectionObserver.js
Created Jul 27, 2021
Using IntersectionObserver to detect whether element is in viewport or not
View IntersectionObserver.js
const target = document.querySelector('.stickyATCtrigger');
function handleIntersection(entries) {
entries.map((entry) => {
if (entry.isIntersecting) {
// element is in viewport
$('body').removeClass('sticky-addtocart-mob');
} else {
// element is out of viewport
$('body').addClass('sticky-addtocart-mob');
}