Skip to content

Instantly share code, notes, and snippets.

View jakewhiteley's full-sized avatar

jake whiteley jakewhiteley

View GitHub Profile
@jakewhiteley
jakewhiteley / FocusManager.js
Last active February 4, 2021 09:58
A class for allowing mobile focus on elements during hashchange
import E from './E'
class FocusManager {
/**
* Call this method to boot up.
*/
static init() {
if (document.location.hash) {
FocusManager.focus(document.getElementById(window.location.hash.replace('#', '')), true)
}
<?php
add_action( 'woocommerce_ship_to_different_address_checked', 'get_persitent_ship_to_different' );
function get_persitent_ship_to_different ( $value )
{
$data = WC()->session->get('form_data');
if ( ! $data || empty($data['ship_to_different_address']) )
return $value;
<?php
add_filter( 'woocommerce_checkout_get_value', 'get_persistent_checkout', 10, 2 );
function get_persistent_checkout ( $value, $index )
{
$data = WC()->session->get('form_data');
if ( ! $data || empty($data[$index]) )
return $value;
return is_bool($data[$index]) ? (int) $data[$index] : $data[$index];
}
<?php
add_action( 'woocommerce_after_checkout_validation', 'set_persitent_checkout' );
function set_persitent_checkout ( $a )
{
$arr = array();
foreach ( $a as $key => $value )
if ( ! empty($value) )
$arr[$key] = $value;
<?php
// create a Set
$set = set( 'first item' );
// Add a new value
$set[] = 'second item';
// Add a new value
foreach ( $set as $val )
print($val);
@jakewhiteley
jakewhiteley / videoTracking.js
Last active April 14, 2016 13:47
Some basic html5 video element events for google analytics. Tracks: play, pause, complete events.
// assumes jquery
$('video').on('pause play ended', function ( e ) {
switch( e.type ) {
case 'play':
var percent = Math.round( e.target.currentTime / e.target.duration * 100 );
ga('send', 'event', 'video', 'play', window.location.href, percent)
break;
case 'pause':
var percent = Math.round( e.target.currentTime / e.target.duration * 100 );
@jakewhiteley
jakewhiteley / woocommerce-persistent-checkout-fields.php
Last active September 29, 2021 21:05
Uses the WC session manager to ensure checkout details are not lost after a customer returns after leaving the checkout page.
<?php
add_action( 'woocommerce_after_checkout_validation', 'set_persitent_checkout' );
add_filter( 'woocommerce_checkout_get_value', 'get_persistent_checkout', 10, 2 );
add_action( 'woocommerce_ship_to_different_address_checked', 'get_persitent_ship_to_different' );
function set_persitent_checkout ( $a )
{
$arr = array();
foreach ( $a as $key => $value )
if ( ! empty($value) )
<?php
function __construct ()
{
parent::__construct();
// accessed via google developer console
$client_email = '****@developer.gserviceaccount.com';
$private_key = file_get_contents(__DIR__ .'/secure.p12');
$scopes = array(\Google_Service_Analytics::ANALYTICS_READONLY);
$user_to_impersonate = '****';
// basil.js
!function(){var e=function(n){return e.utils.extend({},e.plugins,(new e.Storage).init(n))};e.version="0.4.1",e.utils={extend:function(){for(var e="object"==typeof arguments[0]?arguments[0]:{},n=1;n<arguments.length;n++)if(arguments[n]&&"object"==typeof arguments[n])for(var t in arguments[n])e[t]=arguments[n][t];return e},each:function(e,n,t){if(this.isArray(e)){for(var i=0;i<e.length;i++)if(n.call(t,e[i],i)===!1)return}else if(e)for(var r in e)if(n.call(t,e[r],r)===!1)return},tryEach:function(e,n,t,i){this.each(e,function(e,r){try{return n.call(i,e,r)}catch(o){if(this.isFunction(t))try{t.call(i,e,r,o)}catch(o){}}},this)},registerPlugin:function(n){e.plugins=this.extend(n,e.plugins)}};for(var n=["Arguments","Boolean","Function","String","Array","Number","Date","RegExp"],t=0;t<n.length;t++)e.utils["is"+n[t]]=function(e){return function(n){return Object.prototype.toString.call(n)==="[object "+e+"]"}}(n[t]);e.plugins={},e.options=e.utils.extend({namespace:"b45i1",storages:["local","cookie","session","
var AppPath = '/teimr/',
App = blocks.Application({
history: 'pushState'
});
App.View('Navigation', {
options: {
url: AppPath + 'views/navigation.html',
},