Skip to content

Instantly share code, notes, and snippets.

View craigcooperxyz's full-sized avatar

Craig Cooper craigcooperxyz

View GitHub Profile
@craigcooperxyz
craigcooperxyz / gist:f7cf758dc395252b9356
Last active June 10, 2020 04:28
Remove cross-sells from cart in WooCommerce
<?php
/*
* Remove Cross-Sells from the shopping cart page
*
* Copy and paste this code into functions.php to
* remove cross-sells from the cart in WooCommerce.
*
* You may need to remove the opening <?php tag
* before you add it to your functions file.
@craigcooperxyz
craigcooperxyz / functions.php
Last active October 7, 2015 21:40
Add WooCommerce cart link to primary menu when cart is not empty
<?php
/*
*
* Wordpress and WooCommerce
* Add a "Cart" link to the menu when the cart is not empty
*
* When a customer adds an item to their woocommerce cart, a cart
* link will be added to the primary menu.
*
@craigcooperxyz
craigcooperxyz / methods.php
Last active December 7, 2015 23:29
Kirby CMS British Pounds Sterling (GBP) Currency Field Method
<?php
// This field method for Kirby adds a method called GBP (Since extended to gbpsmall or gbplarge)
// Use it like this
// echo $page->price()->gbplarge()
// This example is intended for large figures such as £100,000 or £5,000, there are no decimal places
field::$methods['gbplarge'] = function($field) {
return '£' . number_format($field->value, 0, '.' , ',' );
};
@craigcooperxyz
craigcooperxyz / theme.liquid
Created July 31, 2017 14:00
Better Shopify Titles
<title>
{% if template == 'index' %}
{% if page_title contains 'Welcome' %}
{{ shop.name }} &ndash; Welcome
{% else %}
{{ page_title }}
{% endif %}
{% elsif template == '404' %}
Page Not Found
{% elsif page_title contains shop.name %}
@craigcooperxyz
craigcooperxyz / gist:6494661c21cb550569a25b23b15058b8
Last active October 12, 2020 09:32
Adwords Conversion Tag Shopify
{% if first_time_accessed %}
<script>
gtag('event', 'conversion', {
'send_to': ' ',
'value': {{ total_price | money_without_currency }},
'currency': 'GBP',
'transaction_id': {{ order_number }}''
});
</script>
@craigcooperxyz
craigcooperxyz / gist:8b7c6f9bb1fdd892c0a9d03573ceb819
Created February 26, 2019 22:49
related-products original parisian
<div class="product-template__container custom-call page-width" itemscope itemtype="http://schema.org/Product" id="ProductSection-{{ section.id }}" data-section-id="{{ section.id }}" data-section-type="product" data-enable-history-state="true">
{% comment %}
Number of related items per row,
and number of rows.
{% endcomment %}
{% assign number_of_related_products_per_row = 4 %}
{% assign number_of_rows = 1 %}
@craigcooperxyz
craigcooperxyz / picture.liquid
Created July 1, 2021 14:53
Picture element for images in Shopify
{% assign image = image %}
<picture>
<source srcset="{{ image | img_url: '335x', format: 'pjpg'}}, {{ image | img_url: '670x', format: 'pjpg' }} 2x"
media="(max-width: 375px)">
<source srcset="{{ image | img_url: '750x', format: 'pjpg'}}, {{ image | img_url: '1500x', format: 'pjpg' }} 2x"
media="(max-width: 749px)">
<source srcset="{{ image | img_url: '1500x', format: 'pjpg' }}"
media="(min-width: 750px)">
<img src="{{ image | img_url: '1500x', format: 'pjpg' }}" alt=""
srcset="{{ image | img_url: '1500x', format: 'pjpg' }}">
@craigcooperxyz
craigcooperxyz / auto-apply-shopify-discount.js
Created November 2, 2023 17:22
Automatically add a discount code cookie to a Shopify customer's basket when they land on the page. Useful if you need to apply a discount, but can't use automatic discounts. A bit like using the link Shopify provide, but without the need for the link. Also; will check for existing discount cookie before applying.
(function() {
const discountValue = 'DISCOUNTCODEHERE';
const daysToExpire = 7;
let discountCode;
if (document.cookie.includes("discount_code=")) {
discountCode = document.cookie.split('; ').find(row => row.startsWith('discount_code=')).split('=')[1];
console.log("Discount code is: " + discountCode);
} else {
const date = new Date();