Skip to content

Instantly share code, notes, and snippets.

View atikju's full-sized avatar

MD. Atiqur Rahman atikju

View GitHub Profile
@atikju
atikju / ajaxAddToCart.js
Last active November 4, 2018 11:19
Shopify Ajax - Add product to cart without loading the page
$('form.add_to_cart').on('submit', function(event){
//debugger;
event.preventDefault();
var postUrl = $(this).attr('action');
var postData = $(this).serialize();
//console.log(postData); check what your form posts
$.ajax({
type: "POST",
@atikju
atikju / collectionLink.liquid
Created October 30, 2018 19:33
Shopify - Get first Collection Link of a product
@atikju
atikju / ChangeImageBoldOptionSwatch.js
Last active September 9, 2022 09:48
Shopify - change main image on bold product option swatch click
$(document).ready(function(){
var boldFinder = setInterval(function(){
if($('.bold_option_swatch').length > 0){
$('.bold_option_swatch').eq(0).find('.bold_option_value').on('click', function(){
var clutch_selected = $(this).find('input.sw_607037_276033').attr('data-option_value_key');
console.log(clutch_selected);
//returns url("....");
var imgUrl = $(this).find('span.bold_option_value_swatch span').css('background-image');
//replace the url("
//console.log(imgUrl.toString().slice(5));
@atikju
atikju / ajax-search-form.liquid
Last active April 3, 2025 07:52
Shopify Ajax Search
{% comment %}
This file can be added as a snippet and add it anywhere you want to display
{% endcomment %}
<div id="pageheader">
<div class="util-area">
<div class="search-box">
<form class="search-form" action="/search" method="get" _lpchecked="1">
<i class="icon-mag"></i>
<input type="text" name="q" placeholder="Search" autocomplete="off">
<input type="submit" value="→">
@atikju
atikju / removeItemCart
Created October 25, 2018 17:39
Shopify - Remove item from Cart
{% for item in cart.items %}
<a class="cart-removal" data-line-id="{{ forloop.index }}" href="/cart/change?line={{ forloop.index }}&quantity=0" rel="{{ item.id }}">Remove Item</a>
{% endfor %}
@atikju
atikju / cartDiscount.liquid
Created October 24, 2018 20:45
Shopify - Apply Discount / Coupon / Promo Code on cart page
<div class="cart-promo">
<h2>ENTER A PROMO CODE</h2>
<input type="text" id="devPromo">
<a href="/checkout?discount=none" id="redemDevPromo">Apply Coupon</a>
</div>
<script>
$(document).ready(function(){
//listen to the promo button click
$('#redemDevPromo').on('click', function(event){
//disable the button event
@atikju
atikju / compareTwoArrays.js
Last active October 24, 2018 13:07
JS - compare two arrays and find the mismatched elements
var current = [1, 2, 3, 4, 7, 8],
prev = [1, 2, 4],
isMatch = false,
missing = null;
var i = 0, y = 0,
lenC = current.length,
lenP = prev.length;
for ( ; i < lenC; i++ ) {
@atikju
atikju / ChangeVariantOnImageClick.liquid
Created October 23, 2018 16:22
Shopify - change variant on Product thumbnail image click or change
<script>
$(document).ready(function(){
/*
STEPS:
1. Grab the img id from the src on gallery thumb click
2. loop thru the radio button images and grab the img src
2a. click the button that's it!
*/
/*
@atikju
atikju / realTimeCartUpdate.liquid
Last active October 25, 2018 17:38
Shopify - Real time cart update
{% for item in cart.items %}
<div class="mbl-cart-container" id="DevLine-{{forloop.index}}">
<div class="mbl-quantity">
<p><i class="fas fa-plus" data-line-id="{{ forloop.index }}"></i></p>
<p class="dev-line-qty" id="Q-{{forloop.index}}">{{ item.quantity }}</p>
<p><i class="fas fa-minus" data-line-id="{{ forloop.index }}"></i></p>
</div>
<div class="mbl-line-image">
<a href="{{ item.url }}">
@atikju
atikju / total-stock.liquid
Created October 17, 2018 19:45
Shopify - Display Total Stock Quantity
{% assign total=0 %}
{%for variant in product.variants %}
{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
{% assign total = i %}
{%endfor%}
Total Stock: {{ total }}