Skip to content

Instantly share code, notes, and snippets.

@mikejolley
mikejolley / gist:1425282
Created December 2, 2011 23:12
This snippet lets you edit the icon for the PayPal gateway in WooCommerce.
add_filter('woocommerce_paypal_icon', 'custom_woocommerce_paypal_icon')
function custom_woocommerce_paypal_icon( $url ) {
$url = 'http://yoursite,com/youriconurl.png';
return $url;
}
@mikejolley
mikejolley / gist:1503854
Created December 20, 2011 23:52
Extra Profile Fields - simple code to add extra user meta fields to the back-end, place in functions.php
add_action( 'show_user_profile', 'show_extra_profile_fields', 10 );
add_action( 'edit_user_profile', 'show_extra_profile_fields', 10 );
function show_extra_profile_fields( $user ) { ?>
<h3><?php _e('Extra Profile Information'); ?></h3>
<table class="form-table">
<tr>
@mikejolley
mikejolley / gist:2767607
Created May 22, 2012 08:32
WooCommerce - Default shipping SUB-method 1.5.7/1.6+
add_filter( 'woocommerce_shipping_chosen_method', 'custom_shipping_chosen_method', 10, 2 );
function custom_shipping_chosen_method( $chosen_method, $_available_methods ) {
switch ( $_available_methods[0] ) {
case 'table_rate:0-USPS':
$chosen_method = 'table_rate:0-USPS';
break;
case 'table_rate:1-USPS':
$chosen_method = 'table_rate:1-USPS';
break;
@toddmotto
toddmotto / gist:4655457
Created January 28, 2013 13:22
iOS detect
var iOS = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i);
if (!iOS) {
// Run scripts for anything but iOS
}
@mikejolley
mikejolley / gist:1959165
Created March 2, 2012 15:25
WooCommerce - Change login redirect
/*
* goes in theme functions.php or a custom plugin
*
* By default login goes to my account
**/
add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
function custom_login_redirect( $redirect_to ) {
$redirect_to = 'http://anypage.com';
}
@mikejolley
mikejolley / gist:1965842
Created March 3, 2012 12:17
version of email_order_items_table for use outside of the class
<?php
foreach($order->get_items() as $item) :
$_product = $order->get_product_from_item( $item );
$file = $sku = $variation = $image = '';
if ($show_image) :
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail');
$image = apply_filters('woocommerce_order_product_image', '<img src="'.$src[0].'" alt="Product Image" height="'.$image_size[1].'" width="'.$image_size[0].'" style="vertical-align:middle; margin-right: 10px;" />', $_product);
@scribu
scribu / gist:856587
Created March 5, 2011 18:34
'product' post type + 'color' taxonomy
<?php
// Register the post type and taxonomy
function init_product_cpt() {
register_post_type( 'product', array(
'public' => true,
'label' => __( 'Products', 'my-plugin' )
) );
register_taxonomy( 'color', 'product', array(
@johnpbloch
johnpbloch / protected-roles.php
Created March 13, 2012 14:07
Define 'protected' WordPress roles that can only be deleted by users of at least one protected role. This allows you to enable clients to create, edit, and delete users without deleting your account.
<?php
class JPB_User_Caps {
/**
* An array of all protected roles
* @var array
*/
protected $protectedRoles = array(
'webmaster',
@mikejolley
mikejolley / gist:1965933
Created March 3, 2012 12:50
WooCommerce payment gateway plugin base
<?php
/*
Plugin Name: WooCommerce <enter name> Gateway
Plugin URI: http://woothemes.com/woocommerce
Description: Extends WooCommerce with an <enter name> gateway.
Version: 1.0
Author: WooThemes
Author URI: http://woothemes.com/
Copyright: © 2009-2011 WooThemes.
@mikejolley
mikejolley / gist:2193064
Created March 25, 2012 11:38
WooCommerce - Store customer IP in order meta
// Code goes in functions.php
add_action( 'woocommerce_checkout_update_order_meta', 'wc_store_user_ip' );
function wc_store_user_ip( $order_id ) {
update_post_meta( $order_id, 'Customer IP', $_SERVER['REMOTE_ADDR'] );
}