This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sort WooCommerce shipping methods by cost, lowest to highest | |
*/ | |
add_filter( 'woocommerce_package_rates' , 'sort_woocommerce_available_shipping_methods', 10, 2 ); | |
function sort_woocommerce_available_shipping_methods( $rates, $package ) { | |
if ( !$rates ) return $rates; | |
$tmp = Array(); | |
foreach( $rates as $ma ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); | |
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); | |
function wc_minimum_order_amount() { | |
// Set this variable to specify a minimum order value | |
$minimum = 50; | |
if ( WC()->cart->total < $minimum ) { | |
if( is_cart() ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Deactivate Flat Rate 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_flat_rate_is_available', 'unset_woocommerce_shipping_methods_flat_rate', 10 ,2 ); | |
function unset_woocommerce_shipping_methods_flat_rate ( $return, $package ) { | |
// Setup an array of shipping classes that do not allow Flat Rate Shipping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check the cart for specific shipping classes, remove Free Shipping if they are present | |
* | |
* This code will remove free shipping if a product is in the cart that can not be delivered for free | |
* Assign a shipping class to those products and add the slug to the $freeshipping_array | |
* Multiple shipping classes can be added to the array | |
* | |
* Add the code to your theme functions.php file | |
*/ | |
add_filter( 'woocommerce_package_rates', 'unset_free_shipping_when_product_in_cart' , 10, 1 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add a fixed surcharge to your cart / checkout based on products in cart | |
* Taxes, shipping costs and order subtotal are all included in the surcharge amount | |
* | |
* Change $fixed to set the surcharge to a value to suit | |
* | |
* Change in_array to !in_array to EXCLUDE the $countries array from surcharges | |
* | |
* Uses the WooCommerce fees API | |
* Add to theme functions.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adding a custom field to the invoice | |
* | |
* Uses template tag [[CUSTOMFIELD]] | |
* | |
* custom field name : childname | |
* | |
* 1 - Edit template.php and add the tag in the desired place | |
* 2 - add code to the theme functions.php file | |
*/ |