Skip to content

Instantly share code, notes, and snippets.

View mikejolley's full-sized avatar

Mike Jolley mikejolley

View GitHub Profile
@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);
@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:1967071
Created March 3, 2012 17:26
WooCommerce - Change the placeholder image
/*
* goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)
*
**/
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
@mikejolley
mikejolley / gist:2044101
Last active May 18, 2021 17:02
WooCommerce - Show number of items in cart and total
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
@mikejolley
mikejolley / gist:2044109
Last active April 10, 2024 13:17 — forked from jameskoster/header.php
WooCommerce - Update number of items in cart and total after Ajax
<?php
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
<?php
@mikejolley
mikejolley / gist:2137324
Created March 20, 2012 15:46
Remove WooCommerce CSS from shop page
<?php
add_action( 'wp_enqueue_scripts', 'rcd_exclude_css_from_shop' );
function rcd_exclude_css_from_shop() {
if( is_shop() ) {
wp_dequeue_style('woocommerce_frontend_styles');
}
}
?>
@mikejolley
mikejolley / gist:2176823
Created March 24, 2012 00:44
WooCommerce - Show products from current product category (when viewing a single product)
<?php
if ( is_singular('product') ) {
global $post;
// get categories
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $cats_array[] = $term->term_id;
@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'] );
}
@mikejolley
mikejolley / gist:2263203
Last active June 1, 2019 17:50
WooCommerce - Add custom field (in an order) to the order emails
/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');
function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['How did you hear about us?'] = 'hear_about_us';
return $keys;
}