Skip to content

Instantly share code, notes, and snippets.

View bstonedev's full-sized avatar

Brett Stone bstonedev

View GitHub Profile
@bstonedev
bstonedev / get-all-class-names.js
Last active April 8, 2020 07:06
JavaScript code snippet to get list of all CSS class names in HTML file
var used = [];
var elements = null;
var skipelements = [
'nav'
];
//get all elements
if (typeof document.getElementsByTagName != 'undefined') {
elements = document.getElementsByTagName('*');
}
@bstonedev
bstonedev / performance-boost-code-snippets-functions.php
Created April 6, 2020 21:37
code snippets for functions.php to increase performance
<?php
/**
* Disable jQuery Migrate in WordPress.
*
*/
function crave_remove_jquery_migrate( &$scripts) {
if(!is_admin()) {
$scripts->remove('jquery');
}
@bstonedev
bstonedev / theme-starter-code-snippets-functions.php
Created March 17, 2020 22:07
WP Theme Starter Code Snippets for Functions.php
<?php
/**
* Remove admin bar
**/
add_filter('show_admin_bar', '__return_false');
/**
* Register Custom Post Type
**/
@bstonedev
bstonedev / is_page_template.php
Created March 16, 2020 02:00
Conditional for if Template is being used
<?php
if ( is_page_template( 'template-name.php' ) ) {
// template-name.php is used
}
?>
@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;
}
?>
@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 / weird-ASCII-characters-in-my-csv.txt
Last active January 8, 2025 21:32
Strange characters and their correct replacements that I've found while importing CSV content from client
Weird Character => True Character
’ => '
’ => '
‘ => '
‚Äã => nothing
‚Äã => nothing
‚Ķ => …
• => -
‚Äê => -
-­ => -
@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 / 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 / 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()