Skip to content

Instantly share code, notes, and snippets.

@jimmijazz
jimmijazz / Shopify Script Discounting
Last active January 21, 2024 16:09
Shopify Script Discounting example
# ================================ Customizable Settings ================================
# ================================================================
# Tiered Discounts by Quantity
#
# A list of discount tier offers where:
# - 'product_selector_match_type' determines whether we look for
# products that do or don't match the entered selectors. Can
# be:
# - ':include' to check if the product does match
# - ':exclude' to make sure the product doesn't match
@jimmijazz
jimmijazz / index.js
Created February 3, 2023 22:38
Capture payment for Active Subscribers based on charge_delay and when their order was created
/* Customer orders are recieved as "authorized". The number of days left in their trial is passed as a line
item prop charge_delay. This cron job checks each hour for any orders that are still in authorized state.
If the (order date + charge_delay) is > current date, their trial has ended and we capture payment if
they are still have the "Active Subscriber" tag.
*/
async function captureUnpaidOrders() {
console.log('Debug: Getting unpaid orders');
/* Finds any orders where financial status is authorized.
Then checks if the created_at date + the charge_delay is less than the current date.
@jimmijazz
jimmijazz / Add to Cart with AJAX Add to Cart(Jake)
Last active November 10, 2022 00:06
Add to Cart with AJAX Add to Cart(Jake)
<!-- This code will add an item to the cart on button click. -->
{%- assign has_bib = false -%}
{%- assign has_jersey = false -%}
{%- assign has_bundle = false -%}
{%- for item in cart.items -%}
{% if item.product.type == 'Bib' -%}
{%- assign has_bib = true -%}
{%- elsif item.product.type == 'Jersey' -%}
@jimmijazz
jimmijazz / Add to Cart Prompt Message (Jake)
Last active November 10, 2022 00:06
Add to Cart Prompt Message (Jake)
{%- assign has_bib = false -%}
{%- assign has_jersey = false -%}
{%- assign has_bundle = false -%}
{%- for item in cart.items -%}
{% if item.product.type == 'Bib' -%}
{%- assign has_bib = true -%}
{%- elsif item.product.type == 'Jersey' -%}
{%- assign has_jersey = true -%}
{%- endif -%}
{
"query": "mutation publishablePublish($id: ID!, $input: [PublicationInput!]!) { publishablePublish(id: $id, input: $input) { publishable { availablePublicationCount publicationCount publishedOnCurrentPublication } shop { id } userErrors { field message } }}",
"variables": {
"id": "gid://shopify/Product/{{product.legacyResourceId}}",
"input": [{ "publicationId": "gid://shopify/Publication/25658064918" }]
}
}
@jimmijazz
jimmijazz / Filtering variant options
Created July 7, 2022 08:39
Filtering variant options
/* MTBD Product filtering solution *
This could all be done in liquid as well
Add a product-options id to the fieldset
*/
var options = [[], [], [], []];
var optionsFieldSet = document.getElementById("product-options");
var fieldSetInputs = optionsFieldSet.getElementsByTagName("input");
{% comment %} Renders gift with purchase products that merchant selects {% endcomment %}
<style>
.gallery__item:hover {
cursor: pointer;
}
</style>
<script>
function addToCart(variant_id) {
@jimmijazz
jimmijazz / gist:042ba5f206ef5c93853eab7641dbc599
Created August 26, 2020 06:35
[Shopify] Sample title tag generation with tag filtering
<title>
{{ page_title }}{% if current_tags %}{% assign current_tags_joined = current_tags | join: ', ' %} &ndash; {{ 'general.meta.tags' | t: tags: current_tags_joined }}{% endif %}{% if current_page != 1 %} &ndash; {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}
</title>
payment_gateways = ["Afterpay", "BitPay"] # Gateways to hide
tag = "lowstock" # Tag to look for
lowStockVariantIDS = [] # Will contain variant ID's of low stock items
# Loop over line items to check if any have low stock tag.
# If product doeshave tag, add it to our lowStockVariantIDs array.
Input.cart.line_items.each do |item|
#Note: this won't be very efficient for products with lots of tags
item.variant.product.tags.each do |tag|
@jimmijazz
jimmijazz / cart-message.liquid
Created October 24, 2019 03:16
Add a messag to product page based on cart value
{% assign shipping_threshold = 15000 %} <!-- this is in cents. 15000 = $150-->
{% assign current_cart = shipping_threshold | minus: cart.total_price %}
{{ current_cart }}
{{ cart.total_price }}
{% if cart.total_price < shipping_threshold %}
<p>Add {{ current_cart | money }} to your cart for free express shiping </p>
{% else %}
<p>Qualify for free express shipping!</p>
{% endif %}