Skip to content

Instantly share code, notes, and snippets.

View mikejolley's full-sized avatar

Mike Jolley mikejolley

View GitHub Profile
@mikejolley
mikejolley / query.sql
Created April 26, 2016 09:37
WooCommerce - SQL to Delete users with no orders or posts
DELETE from wp_users where wp_users.ID not in (
SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user'
) AND wp_users.ID not in (
select distinct(post_author) from wp_posts
);
delete from wp_usermeta where wp_usermeta.user_id not in (select ID from wp_users);
@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:6936430
Created October 11, 2013 15:13
Change the PayPal Pro gateway card icons
add_filter( 'woocommerce_paypal_pro_icon', 'custom_woocommerce_paypal_pro_icon' );
function custom_woocommerce_paypal_pro_icon() {
return 'https://yoursite.com/icon.png';
}
@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:3123868
Created July 16, 2012 17:22
WooCommerce - India states
/**
* Code goes in functions.php or a custom plugin.
*/
add_filter( 'woocommerce_states', 'indian_woocommerce_states' );
function indian_woocommerce_states( $states ) {
$states['IN'] = array(
'AP' => __('Andra Pradesh', 'woocommerce'),
'AR' => __('Arunachal Pradesh', 'woocommerce'),
@mikejolley
mikejolley / functions.php
Last active February 5, 2024 15:33 — forked from claudiosanches/functions.php
WooCommerce - Hide shipping rates when free shipping is available.
<?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:3097073
Last active January 18, 2024 17:54
WooCommerce - Unhook/Disable emails
/**
* Code goes in functions.php or a custom plugin.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/
@mikejolley
mikejolley / functions.php
Created July 21, 2016 08:57
WooCommerce - Hide price suffix when product is not taxable.
<?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 / gist:1597957
Created January 12, 2012 01:40
WooCommerce - Replace '' with 'Call for price' when price is left blank
/**
* 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 / functions.php
Created April 14, 2016 18:07
WooCommerce - Disable ALL sale prices with code
<?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 );