Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
ChromeOrange / gist:15faeef86e84271dc6a0
Created December 3, 2014 08:37
Remote GET test for WooCommerce and WooThemes Helper.
/**
* Add to theme functions.php
* Check the System Status
*/
add_filter( 'woocommerce_debug_posting' , 'custom_wp_remote_get_test' );
function custom_wp_remote_get_test( $posting ) {
// WP Remote Get Check
$posting['wp_remote_get']['name'] = __( 'Remote Get', 'woocommerce');
@ChromeOrange
ChromeOrange / gist:9f0870cf034de287bbb4
Created November 14, 2014 07:17
Unset WooCommerce Free Shipping if certain products are in the cart
/**
* Check the cart for specific products, remove Free Shipping method if they are present
*
* Add the code to your theme functions.php file
*/
add_filter( 'woocommerce_package_rates', 'unset_free_shipping_method' , 10, 2 );
function unset_free_shipping_method( $rates, $package ) {
/**
* Setup an array or products
@ChromeOrange
ChromeOrange / gist:79244ff62e6bb105c42c
Created October 13, 2014 16:17
Unset First Class shipping methods from the USPS return in WooCommerce - add the required functions to your theme functions.php file
add_filter('usps_disable_first_class_rate_first-class-mail-parcel', '__return_true');
add_filter('usps_disable_first_class_rate_first-class-mail-large-envelope', '__return_true');
add_filter('usps_disable_first_class_rate_first-class-mail-stamped-letter', '__return_true');
add_filter('usps_disable_first_class_rate_first-class-mail-postcards', '__return_true');
@ChromeOrange
ChromeOrange / gist:b11a74ef8d6968973c3d
Created October 13, 2014 00:33
Set maximum shipping cost for specific Table Rate shipping methods - add to theme functions.php
/**
* Set maximum shipping cost for specific Table Rate shipping methods
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
foreach( $rates as $rate ) {
/**
* Change 10 to your maximum shipping cost and the label to match your Method Title
* shown here https://dl.dropboxusercontent.com/s/5q9hfei3hgnbnt9/2014-10-13%20at%2001.25%20%281%29.png?dl=0
@ChromeOrange
ChromeOrange / gist:09b60834d34b6f2c90d8
Created October 13, 2014 00:07
Set maximum shipping cost depending on delivery country in WooCommerce - add to theme functions.php
/**
* Set maximum shipping cost depending on delivery country in WooCommerce
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
/**
* Create an array of countries for a maximum shipping cost
* eg array('US','CA');
* for US and Canada.
@ChromeOrange
ChromeOrange / gist:56ce4571836429af330d
Created October 12, 2014 14:54
Set a maximum shipping cost for WooCommerce, add this to functions.php - works with all shipping methods
/**
* Set maximum shipping cost in WooCommerce
*/
add_filter( 'woocommerce_package_rates' , 'woocommerce_set_maximum_shipping_cost', 10, 2 );
function woocommerce_set_maximum_shipping_cost( $rates, $package ) {
foreach( $rates as $rate ) {
// Change 10 to your maximum shipping cost
if( $rate->cost > 10 ) {
$rate->cost = 10;
@ChromeOrange
ChromeOrange / gist:3ffbb92d1b08ad7a6fbb
Last active August 29, 2015 14:06
Change USPS package to envelope so that the dimensions are fixed, add to your theme functions.php file
/**
* USPS 4.0 introduced the ability for envelopes to be flexible you can disable this with this function
* Simply set the type to 'envelope' instead of 'package' for any of the flat rate services that USPS lists as envelopes
*/
add_filter( 'usps_flat_rate_boxes', 'custom_usps_flat_rate_boxes' );
function custom_usps_flat_rate_boxes( $flat_rate_boxes ) {
// Priority Mail Express Envelopes
$flat_rate_boxes["d13"]["type"] = 'envelope';
@ChromeOrange
ChromeOrange / gist:bd931a6475cb0d7d5a89
Last active August 29, 2015 14:06
Remove USPS Priority Flat Rate envelopes, add to your theme functions.php file
/**
* Remove USPS Flat rate envelopes from the available options
* Once added the customer will not see any rates for envelopes
*/
add_filter( 'usps_flat_rate_boxes', 'custom_usps_flat_rate_boxes' );
function custom_usps_flat_rate_boxes( $flat_rate_boxes ) {
unset($flat_rate_boxes["d29"]);
unset($flat_rate_boxes["d30"]);
unset($flat_rate_boxes["d63"]);
@ChromeOrange
ChromeOrange / gist:3cb3a16a6560795b972d
Created September 18, 2014 00:20
Add custom order status to WooCommerce 2.2, add to theme functions.php
/**
* Add custom status to order list
*/
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-backorder', array(
'label' => _x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
@ChromeOrange
ChromeOrange / functions.php
Last active August 29, 2015 14:04
Fix PayPal rounding error
/**
* Round Shipping in the event of PayPal errors
*/
add_filter( 'woocommerce_package_rates', 'fix_shipping_rounding_errors' , 10, 2 );
/**
*
*/
function fix_shipping_rounding_errors( $rates, $package ) {