Skip to content

Instantly share code, notes, and snippets.

@KamGraphica
KamGraphica / shopify-add-to-cart
Created May 11, 2016 21:48 — forked from lucased/shopify-add-to-cart
Shopify - Add product to cart automatically
if (typeof Shopify === 'undefined') var Shopify = {};
Shopify.cart = {{ cart | json }};
Shopify.toAdd = 378589397;
var surchargeInCart = false;
var total = 2507; // total in cents.
for (var i=0; i<Shopify.cart.items.length; i++) {
if (Shopify.cart.items[i].id === Shopify.toAdd) {
surchargeInCart = true;
total -= Shopify.cart.items[i].line_price;
@kyleaparker
kyleaparker / gist:5949872
Created July 8, 2013 15:32
Shopify - Show total savings on cart page
{% assign total_saving = 0 %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% capture saving %}{{ item.variant.compare_at_price | minus: item.variant.price }}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
...rest of cart code within for loop
{% endfor %}
Display saving:
@kloon
kloon / gist:4541017
Last active September 13, 2024 22:41
WooCommerce Clear Cart via URL
// check for clear-cart get param to clear the cart, append ?clear-cart to any site url to trigger this
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
@Chrisedmo
Chrisedmo / product-grid.liquid
Created July 31, 2012 11:45
Shopify: Product Grid Item
<div class="grid-product {% cycle ' alpha', '', ' omega' %}" itemscope itemtype="http://schema.org/Product">
{% if product.compare_at_price_min > 0 %}
<!-- SALE BOX -->
<div class="sale-box">
<p>Sale</p>
</div>
{%endif%}
<div class="product-photo">
<a href="{{ product.url | within: collection }}" title="{{ product.title }}">
@carolineschnapp
carolineschnapp / related-products.liquid
Last active February 10, 2025 17:37
Related Products — to add to product.liquid