Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
ChromeOrange / gist:8692924
Created January 29, 2014 17:35
Hide free shipping if certain products are in the cart
/**
* Check the cart for specific products, remove Free Shipping if they are present
*
* Free Shipping method must be enabled
*
* Add the code to your theme functions.php file
*/
add_filter( 'woocommerce_available_shipping_methods', 'free_shipping_when_product_in_cart' , 10, 1 );
function free_shipping_when_product_in_cart( $available_methods ) {
@ChromeOrange
ChromeOrange / gist:9497629
Created March 11, 2014 23:50
Deactivate USPS Shipping if products with specific shipping classes are in the cart. Add the shipping class slugs to the $shippingclass_array array
/**
* Deactivate USPS Shipping if products with specific shipping
* classes are in the cart
*
* Add the shipping class slugs to the $shippingclass_array array
*/
add_filter( 'woocommerce_shipping_usps_is_available', 'unset_woocommerce_shipping_methods_usps', 10 ,2 );
function unset_woocommerce_shipping_methods_usps ( $return, $package ) {
// Setup an array of shipping classes that do not allow USPS Shipping
@ChromeOrange
ChromeOrange / gist:9518080
Last active August 29, 2015 13:57
Check the cart for specific products, remove specific USPS Shipping methods if they are present. See this screen shot for more info http://cld.wthms.co/5Ag1 for more on how to get the USPS shipping values to remove
/**
* Check the cart for specific products, remove specific USPS Shipping methods if they are present
*
* Add the code to your theme functions.php file
*/
add_filter( 'woocommerce_package_rates', 'unset_usps_shipping_methods' , 10, 2 );
function unset_usps_shipping_methods( $rates, $package ) {
/**
* Setup an array or products
@ChromeOrange
ChromeOrange / gist:9832001
Created March 28, 2014 12:51
Set the WooCommerce store city and zipcode / postcode
/**
* Set the store base city and postcode / zipcode
*/
add_filter( 'woocommerce_countries_base_city' , 'set_woocommerce_countries_base_city' );
function set_woocommerce_countries_base_city() {
// Replace with your store town/city
return 'Townland';
}
add_filter( 'woocommerce_countries_base_postcode' , 'set_woocommerce_countries_base_postcode' );
@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 ) {
@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: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: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: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: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');