Skip to content

Instantly share code, notes, and snippets.

@anttiviljami
Last active December 2, 2015 11:09
Show Gist options
  • Save anttiviljami/ad46752d23d622c07f82 to your computer and use it in GitHub Desktop.
Save anttiviljami/ad46752d23d622c07f82 to your computer and use it in GitHub Desktop.
WooCommerce - Apply free shipping to all shipping methods
<?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