Skip to content

Instantly share code, notes, and snippets.

View enamhasan's full-sized avatar

EnamHasan enamhasan

View GitHub Profile
@enamhasan
enamhasan / product.liquid
Created October 21, 2023 02:05
Shopify Select First Variant On Stock When Product Page Loads
{%- comment -%}
If the product first varaiant inventory is 0 then find the variant with inventory and load the product page
{%- endcomment -%}
{%- assign current_variant = product.selected_or_first_available_variant -%}
{%- assign availableVariantId = '' -%}
{%- assign availableVariantFound = false -%}
{%- if current_variant.inventory_quantity <= 0 -%}
{%- for variant in product.variants -%}
@enamhasan
enamhasan / related-article
Created May 2, 2023 03:14
Shopify Related Article By Tag
<div class="related-articles">
<h2 class="h3 text-center">{{ section.settings.related_article_heading }}</h2>
<div class="article_cols articles">
{% assign counter = 0 %}
{% for tag in article.tags %}
{% assign skip_articles = article.handle | split: '.....' %}
{% for related_article in blog.articles %}
{% if related_article.tags contains tag and counter < 3 %}
{% unless skip_articles contains related_article.handle %}
{% assign counter = counter | plus: 1 %}
@enamhasan
enamhasan / gist:e1acfa404396a0f3e69186184a251837
Created June 24, 2022 13:49
SHOPIFY RESTRICTING ACCESS TO A PAGE / ARTICLE / PRODUCT / COLLECTION WITHOUT LOGIN
<html lang="{{ shop.locale }}">
{% if template contains "wholesale" %}
<!-- wholesale Content -->
{% unless customer %}
{% assign send_to_login = true %}
{% endunless %}
{% endif %}
{% if send_to_login and request.path != "/challenge" %}
@enamhasan
enamhasan / scriptTag.js
Created January 11, 2022 13:45
Create ScriptTag via Shopify node react App via GraphQL
import gql from 'graphql-tag';
import { useQuery, useMutation } from '@apollo/react-hooks';
import { Button, Card, Layout, Page, ResourceList, Stack } from '@shopify/polaris';
const CREATE_SCRIPT_TAG = gql`
mutation scriptTagCreate($input: ScriptTagInput!) {
scriptTagCreate(input: $input) {
scriptTag {
id
@enamhasan
enamhasan / advance-product-descripton-shopify
Created February 5, 2021 10:48
Dynamic product description for ElectJet
{% include 'product-template',
description_style: section.settings.description_style,
image_container_width: section.settings.image_size,
section_id: product.id,
social: section.settings.social_enable,
thumbnail_position: section.settings.thumbnail_position,
thumbnail_arrows: section.settings.thumbnail_arrows
%}
{% if settings.enable_product_reviews and settings.reviews_layout == 'full' %}
@enamhasan
enamhasan / Show-inventory Quantity Shopify
Last active March 4, 2022 09:08
Display variant inventory quantiy on product page Shopify
# add this script in product liquid (Just before addtocart form)
<!-- Code added for Inventory in Pipeline -->
<script>
var inv_qty = {};
{% for var in product.variants %}
inv_qty[{{- var.id -}}] = {{ var.inventory_quantity | default: 0 }};
{% endfor %}
</script>
{% if current_variant.inventory_management == "shopify" %}
@enamhasan
enamhasan / Python-Snippets
Last active June 27, 2020 12:26
Python Snippets / Cheat Sheet
#=======Save a dict to json file=============
import json
dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
json = json.dumps(dict)
f = open("dict.json","w")
f.write(json)
f.close()
@enamhasan
enamhasan / mailchimp-newsletter-ajax-signup
Last active July 13, 2022 15:30
Mailchimp-Shopify-Ajax-submission
<div class="success" style="display: none;">{{ settings.success_message }}</div>
{%- if settings.newsletter_form_action != "" -%}
<form id="mc4wp-form-footer" name="nlr" class="mc4wp-form mc4wp-form-{{block.id}} mc4wp-form-basic" method="get" action="{{ settings.newsletter_form_action }}" target="_blank" data-id="{{block.id}}">
<div class="mc4wp-form-fields">
<p class="mailchimp-input-icon">
<label>Email address: </label>
<input type="email" name="EMAIL" placeholder="{{ 'general.newsletter_form.email_placeholder' | t }}" value="{%- if customer -%}{{ customer.email }}{%- endif -%}" required="">
</p>
<p>
<input type="submit" value="{{ 'general.newsletter_form.submit' | t }}">
====Add this block in theme.liquid before closing head </head> =====
{% comment %} ## AGE VERIFICATION -- if user is tagged 'is18', don't load age verification JS. If they aren't, or aren't logged in, load it. {% endcomment %}
{% if customer.tags contains 'is18' %}
{% else %}
{{ 'age-verification.js' | asset_url | script_tag }}
{% endif %}
=======================================
{{ '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js' | script_tag }}
function setShipDate () {
// element to write date to
var shipdate = document.getElementById("js-ship-date");
// Set start date to today - end date in 2 days
var startDate = new Date();
var endDate = "", noOfDaysToAdd = 2, count = 0;
// Map numeric month to name
var month = new Array();