Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
ChromeOrange / gist:8287925
Last active February 25, 2020 04:22
Delete all tax rates from WooCommerce
/**
* Delete ALL WooCommerce tax rates
*
* Add to your theme functions.php then go to woocommerce -> system status -> tools and there will be a delete all tax rates button http://cld.wthms.co/tXvp
*/
add_filter( 'woocommerce_debug_tools', 'custom_woocommerce_debug_tools' );
function custom_woocommerce_debug_tools( $tools ) {
$tools['woocommerce_delete_tax_rates'] = array(
@ChromeOrange
ChromeOrange / gist:8179688
Last active January 1, 2016 17:49
Add fixed surcharge to an order, copy code to your theme functions.php file
/**
* Add a fixed surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*
* Change $fixed to set the surcharge to a value to suit
*
* Add countries to array('US','CA'); to include more countries to surcharge
* http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes for available alpha-2 country codes
*
* Change in_array to !in_array to EXCLUDE the $countries array from surcharges
@ChromeOrange
ChromeOrange / gist:7955195
Created December 14, 2013 02:55
Move WooCommerce Related Products to a tab
/**
* Move WooCommerce Related Products to a tab
*
* Copy code to theme functions.php
*/
// Remove standard Related Products section
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
/**
@ChromeOrange
ChromeOrange / gist:7939277
Last active December 31, 2015 05:09
Check the cart for specific products and show only Free Shipping if they are there in WooCommerce, hide Free Shipping otherwise. Add the code to your theme functions.php file
/**
* Check the cart for specific products and show only free shipping if they are there
*
* Free Shipping method must be enabled
*
* Free Shipping will be hidden if specified products are not found
*
* Add the code to your theme functions.php file
*/
add_filter( 'woocommerce_available_shipping_methods', 'free_shipping_when_product_in_cart' , 10, 1 );
@ChromeOrange
ChromeOrange / gist:7880412
Created December 9, 2013 20:40
Add to your theme functions.php to sort shipping methods by cost
/**
* Sort WooCommerce shipping methods by cost, lowest to highest
*/
add_filter( 'woocommerce_available_shipping_methods' , 'sort_woocommerce_available_shipping_methods' );
function sort_woocommerce_available_shipping_methods( $available_methods ) {
if ( !$available_methods ) return;
$tmp = Array();
foreach( $available_methods as $ma ) {
@ChromeOrange
ChromeOrange / gist:7525565
Created November 18, 2013 10:13
Code for WorldPay subscription cancellation
function change_subscription_status( $profile_id, $new_status ) {
switch( $new_status ) {
case 'Cancel' :
$new_status_string = __( 'cancelled', WC_Subscriptions::$text_domain );
break;
case 'Suspend' :
$new_status_string = __( 'suspended', WC_Subscriptions::$text_domain );
break;
case 'Reactivate' :
@ChromeOrange
ChromeOrange / gist:6638580
Last active August 14, 2017 00:52
Add a surcharge based on delivery country
/**
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*
* Change $percentage to set the surcharge to a value to suit
*
* Add countries to array('US'); to include more countries to surcharge
* http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes for available alpha-2 country codes
*
* Change in_array to !in_array to EXCLUDE the $countries array from surcharges
@ChromeOrange
ChromeOrange / gist:6617327
Last active March 7, 2016 19:29
Show only free shipping in all states except exclusion list, hide free shipping if the customer is in one of those states
/**
* Hide ALL shipping options when free shipping is available and customer is NOT in certain states
* Hide Free Shipping if customer IS in those states
*
* UPDATED FOR WOOCOMMERCE 2.1
*
* Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping
*/
add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 2 );
@ChromeOrange
ChromeOrange / gist:6548750
Last active February 28, 2022 11:18
Modifying Headers in WooCommerce PDF Invoice
/**
* Modifying Headers
*
* Add to your theme functions.php
*/
add_filter( 'pdf_template_table_headings','custom_pdf_template_table_headings' );
function custom_pdf_template_table_headings( $headers ) {
$headers = '<table class="shop_table orderdetails" width="100%">' .
'<thead>' .
'<tr><th colspan="7" align="left"><h2>' . esc_html__('Order Details', PDFLANGUAGE) . '</h2></th></tr>' .
@ChromeOrange
ChromeOrange / gist:6533754
Created September 12, 2013 06:48
Example template.php file used in https://gist.github.com/ChromeOrange/6533569, adds tag [[PDFTERMSCONDITIONS]]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
@page {
margin: 480px 50px 150px 50px;
}
#header {
position: fixed;
left: 0px;