Skip to content

Instantly share code, notes, and snippets.

@jimmijazz
jimmijazz / gist:042ba5f206ef5c93853eab7641dbc599
Created Aug 26, 2020
[Shopify] Sample title tag generation with tag filtering
View gist:042ba5f206ef5c93853eab7641dbc599
<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>
View hide variants (not products) based on tag.rb
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|
View The Pedla Shopify Script Discounting
# ================================ 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
View Pedla 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' -%}
View Pedla 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 -%}
@jimmijazz
jimmijazz / cart-message.liquid
Created Oct 24, 2019
Add a messag to product page based on cart value
View cart-message.liquid
{% 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 %}
View Discount Product Type A if Product type B is in cart
# EG - I want to offer 15% off all cycling bib shorts when any of our cycling jerseys are purchased.
# Assumes no limit on how many of these products can be discounted in one cart
cartDiscountAmount = 15 # (Int) Percentage discount to apply. 15 = 15%
cartDiscountMessage = "15% off Pedla bibs" # (String) Message to apple when discounting
cartDiscountCondition = false # (Boolean) Should the cart discount conditions be applied
discountConditionalProductType = "Electronics" # (String) If this product type is in the cart other products may be discounted
discountTargetProductType = "Music" # (String) The product type that should be discounted.
View Shopify Scripts - hiding shipping rates if under total accounting for discounts (WIP)
totalCartPrice = 0
Input.cart.line_items.each do |item|
totalCartPrice += item.line_price.cents
end
Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
shipping_rate.name.upcase.start_with?("EXPRESS")
end
View Apply discount to all except those that have a certain tag
# This script will apply a 100% discount to all shipping methods if the customers who have a tag in the VIP_CUSTOMER_TAG array
# Define the tag that identifies VIP customers.
VIP_CUSTOMER_TAG = ['trade', 'wholesale']
if !Input.cart.customer.nil? # Check there is actually a customer
VIP_CUSTOMER_TAG.each do |tag| # Loop over their tags
if Input.cart.customer.tags.include?(tag.downcase) # Check for upper or lower case
Input.shipping_rates.each do |shipping_rate| # Loop over shipping rates
shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping for Trade and Wholesale Customers!") # Apply discount
View Hide Payment Gateway if any Line Items have Tag
tag = "hide" # If any line items have this tag, the gateway would be hidden
payment_gateways = ["Credit card", "BitPay"] # Any gateways in this array will be hidden
hide = false
Input.cart.line_items.each do |item|
if item.variant.product.tags.include?(tag)
hide = true
break
end
end