Skip to content

Instantly share code, notes, and snippets.

View bstonedev's full-sized avatar

Brett Stone bstonedev

View GitHub Profile
@bstonedev
bstonedev / Listing Shopify Products by Tag
Created March 29, 2019 08:33
loop through all unique tags across your products, list products according to those unique tags.
Demo: https://stone-digital-test.myshopify.com/pages/tag-loop-example
<!-- Step 1) create comprehensive list of all tags ie. tags_list -->
{% capture tags_list %}
{% for product in collections.all-products.products %}
{% for tag in product.tags %}
{{ tag | strip | strip_newlines }}{% if forloop.last == true %}{% else %},{% endif %}
{% endfor %}{% if forloop.last == true %}{% else %},{% endif %}
{% endfor %}
{% endcapture %}
@bstonedev
bstonedev / ShopifyCheatsheet.md
Last active April 23, 2022 11:26
Shopify Liquid Cheatsheet

The Loops

-- product in all-products

{% for product in collections.all-products.products %}
   {{ product.title }}
   <ul>
       <li>{{ variant.image.src }} - Variant Image Object</li>
       <li>{{ variant.price }} - Variant Price</li>
@bstonedev
bstonedev / cheatsheet-ascii-unicode-quotation-marks.md
Created February 10, 2020 07:12
A Guide to ASCII, Unicode, UTF-8 and UTF-16 for quote marks and dashes.
UTF-16 UTF-8 DESCRIPTION SAMPLE
\U0022 \x22 QUOTATION MARK "
\U0027 \x27 APOSTROPHE '
\U201C \xe2\x80\x9c LEFT DOUBLE QUOTE
\U201D \xe2\x80\x9d RIGHT DOUBLE QUOTE
\U2018 \xe2\x80\x98 LEFT SINGLE QUOTE
\U2019 \xe2\x80\x99 RIGHT SINGLE QUOTE
\u002d \x2d A HYPHEN -
\u2013 \xe2\x80\x93 AN EN DASH
@bstonedev
bstonedev / WC->get_cart().php
Created February 11, 2020 00:17
$array = WC_Cart::get_cart();
Array(
[key] => b2518060b99e87b333629133e91ee828
[product_id] => 57317
[variation_id] => 0
[variation] => Array
(
)
[quantity] => 1
[data_hash] => b5c1d5ca8bae6d4896cf1807cdf763f0
[line_tax_data] => Array
@bstonedev
bstonedev / WC->get_cart().php
Last active February 11, 2020 00:24
Example output of single product object - retrieved via `$cart_obj->get_cart();` then `print_r($value)` in loop
Array(
[key] => ############################
[product_id] => 57317
[variation_id] => 0
[variation] => Array()
[quantity] => 1
[data_hash] => ##########################
[line_tax_data] => Array(
[subtotal] => Array()
[total] => Array()
@bstonedev
bstonedev / nested-arrays.js
Last active February 16, 2020 07:25
Nested Arrays in JavaScript / Multi Level Array / Multidimensional Array
// this is to create a Nested Array
// eg. multiLevelArray[0][0]
var multiLevelArray = new Array(loop.length);
for (var k = 0; k < loop.length; k++) {
multiLevelArray[k] = new Array(loop[k].valueA, loop[k].valueB);
}
@bstonedev
bstonedev / list-all-products-from-all-collections.liquid
Last active February 18, 2020 07:33
Code Snippet: List all collections within a Shopify Page
<div class="grid-container">
{% for collection in collections %}
<div class="grid-item">
<div class="grid-item-photo">
<a href="{{ collection.url }}">
{% for image in collection.images limit:1 %}<img src="{{ image }}" alt="{{ image.alt | escape }}">{% endfor %}
</a>
</div>
<div class="grid-item-title">
<a href="{{ collection.url }}">{{ collection.title }}</a>
@bstonedev
bstonedev / weird-ASCII-characters-in-my-csv.txt
Last active October 17, 2022 00:26
Strange characters and their correct replacements that I've found while importing CSV content from client
Weird Character => True Character
’ => '
’ => '
‘ => '
‚Äã => nothing
‚Äã => nothing
‚Ķ => …
• => -
‚Äê => -
-­ => -
@bstonedev
bstonedev / woo-checkout-fields-edit.php
Created March 8, 2020 21:26
Override / set / replace / clear WooCommerce checkout page field values
<?php
/**
* Pre-populate Woocommerce checkout fields
* Note that this filter populates shipping_ and billing_ fields with a different meta field eg 'first_name'
*/
add_filter('woocommerce_checkout_get_value', function($input, $key ) {
if($key == 'billing_first_name') {
return 'NEW FIRST NAME';
}
if($key == 'billing_last_name') {
@bstonedev
bstonedev / woocommerce-discount-amount.php
Created March 13, 2020 00:48
Find discount amount for WooCommerce Product
<?php
$product = wc_get_product($product_id);
if( $product->is_on_sale() ) {
$discount = $product->get_regular_price() - $product->get_sale_price();
}
else {
$discount = 0;
}
?>