Skip to content

Instantly share code, notes, and snippets.

View lukecav's full-sized avatar
Infinite data generation engine

Luke Cavanagh lukecav

Infinite data generation engine
View GitHub Profile
@lukecav
lukecav / remove_wc_data.sql
Created September 7, 2018 20:12 — forked from growdev/remove_wc_data.sql
Remove WooCommerce orders, subscriptions, non admin users
# GET number of orders
select count(*)from wp_posts where post_type = 'shop_order';
# DELETE ORDERS
delete from wp_postmeta where post_id in (
select ID from wp_posts where post_type = 'shop_order');
delete from wp_posts where post_type = 'shop_order';
# DELETE order refunds
@lukecav
lukecav / wc-modify-email.php
Created July 9, 2018 19:30 — forked from woogists/wc-modify-email.php
[WooCommerce StoreCredit] Modify email sent
/* Code goes in theme functions.php */
add_filter( 'woocommerce_email_template_store_credit', 'wc_ninja_store_credit_template' );
function wc_ninja_store_credit_template() {
return get_stylesheet_directory() . "/woocommerce/customer-store-credit.php";
}
@lukecav
lukecav / wc-change-default-country-non-existing.php
Created July 9, 2018 19:25 — forked from woogists/wc-change-default-country-non-existing.php
[Frontend Snippets] Change the default country on the checkout (non-existing users only)
/**
* Change the default country on the checkout for non-existing users only
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country', 10, 1 );
function change_default_checkout_country( $country ) {
// If the user already exists, don't override country
if ( WC()->customer->get_is_paying_customer() ) {
return $country;
}
@lukecav
lukecav / hide-all-shipping-keep-local-free.php
Created July 9, 2018 19:25 — forked from woogists/hide-all-shipping-keep-local-free.php
[General Snippets][Hide other shipping methods, but keep "Local pickup" when “Free Shipping” is available]
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( 'free_shipping' === $rate->method_id ) {
@lukecav
lukecav / wc-query-woocommerce-active.php
Created July 9, 2018 19:25 — forked from woogists/wc-query-woocommerce-active.php
[Theming Snippets] Query whether WooCommerce is activated
/**
* Check if WooCommerce is activated
*/
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
function is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
}
}
@lukecav
lukecav / functions.php
Last active January 12, 2018 19:40 — forked from LaurenaRehbein/remove_price.php
Remove the price string from variable subscription products in WooCommerce
function wc_remove_var_subscriptions_price() {
return '';
}
add_filter( 'woocommerce_variable_subscription_price_html', 'wc_remove_var_subscriptions_price' );
@lukecav
lukecav / functions.php
Last active January 12, 2018 19:35 — forked from LaurenaRehbein/stripe-icon-filter.php
Change the WooCommerce Stripe Payment Gateway 4.0 icons back to color.
add_filter( 'wc_stripe_payment_icons', 'change_my_icons' );
function change_my_icons( $icons ) {
// var_dump( $icons ); to show all possible icons to change.
$icons['visa'] = '<img src="http://woocommerce-ext.reh/wp-content/plugins/woocommerce/assets/images/icons/credit-cards/visa.svg" />';
$icons['mastercard'] = '<img src="http://woocommerce-ext.reh/wp-content/plugins/woocommerce/assets/images/icons/credit-cards/mastercard.svg" />';
$icons['amex'] = '<img src="http://woocommerce-ext.reh/wp-content/plugins/woocommerce/assets/images/icons/credit-cards/amex.svg" />';
return $icons;
}
@lukecav
lukecav / functions.php
Last active January 11, 2018 03:45 — forked from woogist/functions.php
Change the price string globally for WooCommerce Subscriptions
function wc_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'every 3 months', 'per season', $pricestring );
return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );
@lukecav
lukecav / functions.php
Created January 11, 2018 03:14 — forked from eduwass/functions.php
WooCommerce Product Bundles - Check if cart contains a Product Bundle Container
<?php
/**
* Checks if the cart contains a product bundle
* @return [bool]
*/
function cart_contains_product_bundle(){
global $woocommerce;
$contains_product_bundle = false;
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
// if cart has items
@lukecav
lukecav / woocommerce-change-gravity-forms-product-addons-select-options-text.php Change the product archive Select Options text in GravityForms Product Addons for WooCommerce using the filter woocommerce_gforms_add_to_cart_text
function change_gravity_add_to_cart() {
return 'Changed Text';
}
add_filter( 'woocommerce_gforms_add_to_cart_text', 'change_gravity_add_to_cart' );