Skip to content

Instantly share code, notes, and snippets.

:shipit:
Working from home

Mike Jolley mikejolley

View GitHub Profile
@mikejolley
mikejolley / functions.php
Last active Nov 1, 2018
WooCommerce 3.3 - Hide uncategorized category from the shop page on the frontend
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_filter( 'woocommerce_product_subcategories_args', 'custom_woocommerce_product_subcategories_args' );
function custom_woocommerce_product_subcategories_args( $args ) {
$args['exclude'] = get_option( 'default_product_cat' );
return $args;
@mikejolley
mikejolley / double-serialized-attributes-fixer.php
Created May 16, 2017
Small drop-in plugin to fix double-serialized product attributes (they are no longer double-unserialized in WC Core)
View double-serialized-attributes-fixer.php
<?php
/**
* Plugin Name: Double serialized attributes fixer
* Description: Adds a tool to fix double serialized attributes in WooCommerce.
* Version: 0.0.9
* Author: Mike J
* Requires at least: 4.4
* Tested up to: 4.7
*/
if ( ! defined( 'ABSPATH' ) ) {
@mikejolley
mikejolley / functions.php
Created Apr 7, 2017
WooCommerce 3.0 - Disable deferred email sending
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_filter( 'woocommerce_defer_transactional_emails', '__return_false' );
@mikejolley
mikejolley / functions.php
Created Feb 10, 2017
WooCommerce - Notify admin when a new customer account is created
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id ) {
wp_send_new_user_notifications( $customer_id, 'admin' );
}
@mikejolley
mikejolley / functions.php
Created Jul 21, 2016
WooCommerce - Hide price suffix when product is not taxable.
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_filter( 'woocommerce_get_price_suffix', 'custom_woocommerce_get_price_suffix', 10, 2 );
function custom_woocommerce_get_price_suffix( $price_display_suffix, $product ) {
if ( ! $product->is_taxable() ) {
return '';
@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 / gist:c4606aa52754b334f0f1bbe7e5b5ca6b
Created Jun 30, 2016
WooCommerce - remove payment method from emails
View gist:c4606aa52754b334f0f1bbe7e5b5ca6b
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_filter( 'woocommerce_get_order_item_totals', 'custom_woocommerce_get_order_item_totals' );
function custom_woocommerce_get_order_item_totals( $totals ) {
unset( $totals['payment_method'] );
return $totals;
@mikejolley
mikejolley / functions.php
Last active Feb 27, 2019 — forked from claudiosanches/functions.php
WooCommerce - Hide shipping rates when free shipping is available.
View functions.php
<?php
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@mikejolley
mikejolley / gist:cd67b0baf1c3767bb29f76471fea120b
Last active Jun 1, 2017
WooCommerce - Add all upsells of a product to the cart via custom link
View gist:cd67b0baf1c3767bb29f76471fea120b
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
* Product must have upsells, and this works with simple products only.
* Example link: yoursite.com?add-upsells-to-cart=X, X being your product ID.
*/
add_action( 'wp_loaded', 'bulk_upsell_add_to_cart_action', 20 );
function bulk_upsell_add_to_cart_action() {
@mikejolley
mikejolley / functions.php
Created May 24, 2016
WooCommerce - enable free shipping only if product class is found in cart.
View functions.php
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php. Free Shipping Method must be enabled.
*/
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'free_shipping_based_on_cart_shipping_class' );
function free_shipping_based_on_cart_shipping_class( $is_available ) {
/**
You can’t perform that action at this time.