Skip to content

Instantly share code, notes, and snippets.

:shipit:
Working from home

Mike Jolley mikejolley

:shipit:
Working from home
Block or report user

Report or block mikejolley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikejolley
mikejolley / gist:1604009
Created Jan 13, 2012
WooCommerce - Add a special field to the checkout, order emails and user/order meta
View gist:1604009
/**
* 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>';
/**
@mikejolley
mikejolley / functions.php
Created Jul 2, 2016
WooCommerce - Redirect external products offsite (disable single listings)
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_action( 'template_redirect', 'redirect_external_products' );
function redirect_external_products() {
global $post;
@mikejolley
mikejolley / functions.php
Last active Nov 8, 2019
WooCommerce - Split shipping class items into a new package and limit shipping methods
View functions.php
/**
* This function loops over cart items, and moves any item with shipping class 'special-class' into a new package.
* The new package in this example only takes flat rate shipping.
*/
function split_special_shipping_class_items( $packages ) {
$found_item = false;
$special_class = 'special-class'; // edit this with the slug of your shippig class
$new_package = current( $packages );
$new_package['contents'] = array();
$new_package['contents_cost'] = 0;
@mikejolley
mikejolley / gist:1751128
Last active Nov 7, 2019
WooCommerce - Hide loop buttons for out of stock items
View gist:1751128
/*
* Override via functions.php
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart() {
global $product;
if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) return;
woocommerce_get_template('loop/add-to-cart.php');
}
}
@mikejolley
mikejolley / gist:1597957
Created Jan 12, 2012
WooCommerce - Replace '' with 'Call for price' when price is left blank
View gist:1597957
/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
return 'Call for price';
}
@mikejolley
mikejolley / gist:2044109
Last active Nov 4, 2019 — forked from jameskoster/header.php
WooCommerce - Update number of items in cart and total after Ajax
View gist:2044109
<?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:1622323
Created Jan 16, 2012
WooCommerce - Change default catalog sort order
View gist:1622323
/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby');
function custom_default_catalog_orderby() {
return 'date'; // Can also use title and price
}
@mikejolley
mikejolley / gist:1860056
Created Feb 18, 2012
WooCommerce - Override billing fields
View gist:1860056
add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
function custom_woocommerce_billing_fields( $fields ) {
// Over-ride a single label
$fields['billing_first_name']['label'] = 'Your label';
// Over-ride a single required value
$fields['billing_first_name']['required'] = false;
@mikejolley
mikejolley / gist:2176823
Created Mar 24, 2012
WooCommerce - Show products from current product category (when viewing a single product)
View gist:2176823
<?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 / functions.php
Created Apr 14, 2016
WooCommerce - Disable ALL sale prices with code
View functions.php
<?php
/**
* After adding this code to theme functions.php, ensure you clear transients via WC > System Status > Tools
*/
add_filter( 'woocommerce_get_sale_price', '__return_empty_string' );
add_filter( 'woocommerce_variation_prices_sale_price', '__return_empty_string' );
add_filter( 'woocommerce_variation_prices_price', 'custom_get_price', 10, 2 );
add_filter( 'woocommerce_get_price', 'custom_get_price', 10, 2 );
You can’t perform that action at this time.