Skip to content

Instantly share code, notes, and snippets.

View twoelevenjay's full-sized avatar
🏠
Working from home

Leon Francis Shelhamer twoelevenjay

🏠
Working from home
View GitHub Profile
@twoelevenjay
twoelevenjay / woocommerce-support-email.php
Created July 20, 2014 21:46
Function to have WooCommerce send an automatic support email to the customer for orders that switch to a status of cancelled.
<?php
add_action('woocommerce_order_status_changed', 'send_support_email');
function send_support_email($order_id) {
$order_data = new WC_Order($order_id);
global $woocommerce;
$mailer = $woocommerce->mailer();
if ($order_data->status=='cancelled') {
$to = $order_data->billing_first_name . ' <' . $order_data->billing_email . '>';
@twoelevenjay
twoelevenjay / woocommerce-heads-up-email.php
Created July 20, 2014 21:48
Function to have WooCommerce send an automatic heads up email to the shop owner for orders that switch to a status of on-hold.
add_action('woocommerce_order_status_changed', 'send_hold_email');
function send_hold_email($order_id) {
$order_data = new WC_Order($order_id);
if ($order_data->status=='on-hold') {
global $woocommerce;
$mailer = $woocommerce->mailer();
$message = $mailer->wrap_message(
__( 'Order placed On-hold', 'woocommerce' ),
@twoelevenjay
twoelevenjay / gist:8f83b7db58696e1181b4
Created October 3, 2015 04:49 — forked from corsonr/gist:9152652
WooCommerce : add custom fields to product variations
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 );
/**
@twoelevenjay
twoelevenjay / gist:e8a63c3b12ee32521dee
Last active October 31, 2015 09:44 — forked from dasher/gist:4391953
Litecoin Supernodes
addnode=83.169.3.31
addnode=82.226.138.81
addnode=93.62.173.122
addnode=94.23.253.228
addnode=91.121.174.223
addnode=188.120.246.137
addnode=12.23.127.175
addnode=99.243.145.178
addnode=79.142.22.72
addnode=198.23.159.10
@twoelevenjay
twoelevenjay / admin-create-new-customer-on-frontend-checkout.php
Created December 12, 2015 02:16
Allow admins to manually enter new WooCommerce orders from the frontend checkout field.
<?php
// Allow admins to manually enter new WooCommerce orders from the frontend checkout field.
// Hook the woocommerce_checkout_customer_id filter found in the WC_Checkout class.
add_filter( 'woocommerce_checkout_customer_id', 'change_current_user_id_to_new_user' );
function change_current_user_id_to_new_user( $user_id ) {
//Check if logged in user is admin.
if ( current_user_can( 'manage_options' ) ) {
<?php
/*
* Sometimes you might find a WooCommerce shop ends up with products that
* have an attribute assigned but no terms selected for that attribute.
* I used this script to bulk delete any empty attribute from 117 products.
* In my case I was able to simply hook it to 'init', however when dealing
* with 500 plus products this may cause a timeout error. In these cases
* I would make this an AJAX function and create a JS script to handle multple
* requests in chunks.
<!doctype html>
<!-- Bootstrap Under Construction Boilerplate -->
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<?php
/*
* Conditionally hide shipping methid, based
* on shipping class found in the cart
*/
function is_shipping_class_in_cart( $shipping_class ) {
$is_shipping_class_in_cart = false;
@twoelevenjay
twoelevenjay / pr-schedule-woocommerce.md
Last active July 28, 2016 00:53
Schedule of PRs for the update variations from cart feature of WooCommerce

Schedule of PRs for the update variations from cart feature of WooCommerce

I believe these are the best steps of implementing the changes to WooCommerce needed to add the ability for customers to update the variations of products that have already been added to the cart. These steps represent individual smaller pull requests per @mikejolley.

You can see all of the changes together by comparing here.

PR step 1

  1. Add new files. Don't touch core at all. The cart-update-variation.js file takes the available varitions that are loaded with wp_localize_script() and compares them to the selected values of the attribute select fields. When a match is found the it will update a hidden field with variation id. This field is used when updating the cart. This vsariation id update is
@twoelevenjay
twoelevenjay / make_ifttt_clickable.php
Created January 16, 2017 16:33
make_ifttt_clickable.php
<?php
add_filter( 'the_content', 'make_ifttt_clickable', 1 );
function make_ifttt_clickable( $content ) {
$reg_ex = '/http:\/\/ift.tt(\/\S*)?/';
$link = '<a target="_blank" href="http://ift.tt${1}">http://ift.tt${1}</a>';
return preg_replace( $reg_ex, $link, $content );
}