Skip to content

Instantly share code, notes, and snippets.

@nikikozak
nikikozak / component-size-guide.css
Created January 7, 2023 13:33
CSS code for the size guide feature.
/* Size Guide Modal Window */
.sizeguide_background {
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
top: 0;
bottom: 0;
1. Include the component-size.guide.css file:
{{ 'component-size-guide.css' | asset_url | stylesheet_tag }}
2. After the closing endstyle tag, paste the following code:
<script src="{{ 'size-guide.js' | asset_url }}" defer="defer"></script>
{% comment %} Sizing chart {% endcomment %}
@nikikozak
nikikozak / main-product.liquid (schema)
Created January 7, 2023 12:09
Replace the existing variant picker block schema with this code.
{
"type": "variant_picker",
"name": "t:sections.main-product.blocks.variant_picker.name",
"limit": 1,
"settings": [
{
"type": "select",
"id": "picker_type",
"options": [
{
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
{% if first_time_accessed %}
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: "{{ order.order_number }}",
value: {{ total_price | times: 0.01 }},
tax: {{ tax_price | times: 0.01 }},
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXXXXXXX');
{% if first_time_accessed %}
gtag("event", "purchase", {
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXXXXXXX');
</script>
@nikikozak
nikikozak / theme.liquid
Last active July 17, 2023 07:44
Inventory notice: Declare a variable
// Declare a variable in the main theme file. Put before the closing </head> tag.
<script>
var variantStock = {};
</script>
@nikikozak
nikikozak / global.js
Last active July 17, 2023 07:45
Inventory notice: Add JS for updating the inventory quantity
// In the file, find the following function and replace the code with the following code snippet.
toggleAddButton(disable = true, text, modifyClass = true) {
const productForm = document.getElementById(`product-form-${this.dataset.section}`);
if (!productForm) return;
const addButton = productForm.querySelector('[name="add"]');
const addButtonText = productForm.querySelector('[name="add"] > span');
const inventoryNotice = document.getElementById('inventoryNotice');
const inventoryHtml = `Only ${variantStock[this.currentVariant.id]} in stock!`;
const inventoryHighHtml = `More than 10 in stock!`;
@nikikozak
nikikozak / main-product.liquid
Last active May 17, 2023 12:33
Inventory notice: Render block on product pages
{%- when 'inventory_notice' -%}
{% assign current_variant = product.selected_or_first_available_variant %}
<div id="inventoryNotice" class="price">
{% if current_variant.available %}
{% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= 10 %}
Only {{ current_variant.inventory_quantity }} in stock!
{% elsif current_variant.inventory_quantity > 10 %}
More than 10 in stock!
{% endif %}
{% endif %}