Skip to content

Instantly share code, notes, and snippets.

View hezninja's full-sized avatar

hez.ninja hezninja

View GitHub Profile
@hezninja
hezninja / checkout-additional-scripts.liquid
Created July 29, 2022 00:25
Enhanced Conversions for Shopify
<!-- Global site tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-XXXXXXXXX', {'allow_enhanced_conversions': true});
</script>
@hezninja
hezninja / product.liquid
Created July 7, 2022 03:07
Shopify Ajax API - Add Item to cart
<script>
var items = ['id': VARIANT_ID,'quantity': 1];
function addToCart(items){
let formData = {
'items': items
};
fetch(window.Shopify.routes.root + 'cart/add.js', {
@hezninja
hezninja / product.liquid
Last active June 22, 2022 05:11
Shopify Single Line Text (List) Iteration
<!--
Probably a bit hacky and i've overlooked an easier solution...
But for some reason looping through a "Single line text (List)" type metafield is problematic.
At least for me.
-->
{% assign singleLineList = product.metafields.custom.exampleList | replace:'"','' | replace:'[','' | replace:']','' | split: ',' %}
{% for listItem in singleLineList %}
<!-- Do stuff -->
@hezninja
hezninja / blog.liquid
Created June 20, 2022 01:05
Shopify blog sub-menu using tags
<!--
Create a sub-menu for the blog based on specific tags, grouped by a prefix.
Example menu: "Yamaha | Suzuki | Harley-Davidson etc"
Method: Tag a blog post with "specificPrefix_Yamaha"
-->
{% assign brandedBlogTagList = '' %}
{% for blogTag in blog.all_tags %}
@hezninja
hezninja / product.liquid
Last active June 20, 2022 00:33
Assign a specific Shopify collection to a product for a custom breadcrumb using the collection handle and a metafield
{% assign productCollections = product.collections | map:'handle' %}
{% if productCollections contains product.metafields.my_fields.breadcrumb %}
<a href="/collections/{{product.metafields.my_fields.breadcrumb}}">{{collections[product.metafields.my_fields.breadcrumb].title}}</a>
{%- endif -%}