Last active
December 2, 2015 11:09
-
-
Save anttiviljami/ad46752d23d622c07f82 to your computer and use it in GitHub Desktop.
WooCommerce - Apply free shipping to all shipping 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
<?php | |
/** | |
* Plugin name: WooCommerce - Apply free shipping to all shipping methods | |
* Plugin URI: https://gist.github.com/anttiviljami/ad46752d23d622c07f82 | |
* Description: If Free Shipping is available, make other shipping options cost 0 and disable the 'Free Shipping' method | |
* Version: 1.0 | |
* Author: anttiviljami | |
* Author: https://github.com/anttiviljami | |
* License: GPLv3 | |
*/ | |
add_filter( 'woocommerce_package_rates', 'wc_apply_free_shipping_to_all_methods', 10, 2 ); | |
function wc_apply_free_shipping_to_all_methods( $rates, $package ) { | |
if( isset( $rates['free_shipping'] ) ) { | |
unset( $rates['free_shipping'] ); | |
foreach( $rates as $rate ) { | |
$rate->cost = 0; | |
$rate->taxes = array(); | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment