Skip to content

Instantly share code, notes, and snippets.

@mikejolley
mikejolley / gist:1604009
Created January 13, 2012 00:31
WooCommerce - Add a special field to the checkout, order emails and user/order meta
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
/**
@ffdead
ffdead / if-resolution.scss
Created December 5, 2012 12:32
SASS resolution media query mixin
/* @author 14islands.com
* SASS mixins for future proof resolution media query
*/
@mixin if-min-resolution($dppx) {
@include if-resolution(min, $dppx) {
@content;
}
}
@cowboy
cowboy / bocoup-training-more-efficient-event-handlers.js
Created February 12, 2013 21:38
Bocoup training: More Efficient jQuery Event Handlers
// Straightforward + simple.
$("button").on("click", function(event) {
event.preventDefault();
var button = $(this);
var numberElem = button.find(".number");
var number = Number(numberElem.text()) - 1;
numberElem.text(number);
if (number === 0) {
button.prop("disabled", true);
button.off("click");
@wycks
wycks / image_optimize-wordpress.php
Last active December 16, 2020 01:48
Remove WordPress full size images from being inserted into a post + option to and add max size to to prevent users from inserting massive images.
<?php
/**
*
* This removes the ability to add the FULL image size into a post, it does not alter or delete the image
* Add whataever extra image sizes to the insert dropdown in WordPress you create via add_image_size
*
* For now we have to do it this way to make the labels translatable, see trac ref below.
*
* If your theme has $content_width GLOBAL make sure and remove it
@FWeinb
FWeinb / jquery.cache.js
Last active March 25, 2021 03:53
Simple lazy evaluation pattern
(function($){
$.fn.cache = function (key, create, use){
var data = this.data(key);
if (!data){
data = create();
this.data(key, data);
}
return use(data);
};
})(jQuery);
@mglaman
mglaman / wp-widget-custom-classes.php
Created June 12, 2013 02:10
Allows the ability to add custom classes to WordPress widgets (just through filter, does not add form.)
<?php
//Hook into dynamic_sidebar_params filter
//found in dynamic_siderbar ( wp-include/widgets.php ) line 886
add_filter( 'dynamic_sidebar_params', 'extend_widgets_sidebar_params', 10);
//I have my classes stored within an array in an option called widget_classes
if((!$widget_classes = get_option('widget_classes')) || !is_array($widget_classes) ) $widget_classes = array();
/* Params callback on setting widget params */
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
get_option( 'woocommerce_view_order_page_id' );
get_option( 'woocommerce_terms_page_id' );
@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active January 8, 2024 13:24
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
anonymous
anonymous / class-piklist.php
Created February 15, 2014 09:35
includes/class-piklist.php - Solution to getting piklist working on windows (and in my case, on a dropbox hardlinked folder structure)
<?php
if (!defined('ABSPATH'))
{
exit;
}
class PikList
{
public static $version;
@einkoro
einkoro / password_bcrypt.php
Last active May 10, 2016 16:52
Must-use plugin for WordPress to swap phpass to PHP 5.5's new password_hash and password_verify using bcrypt
<?php
/**
* Plugin Name: WP PASSWORD_BCRYPT
* Plugin URI: http://bitpiston.com/
* Description: Replaces wp_hash_password and wp_check_password's phpass hasher with PHP 5.5's password_hash and password_verify using bcrypt.
* Author: BitPiston Studios
* Author URI: http://bitpiston.com/
* Version: 1.2
* Licence: BSD
*/