Guest User

Untitled

a guest
Sep 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /**
  2. * Hide shipping rates when free shipping is available.
  3. * Updated to support WooCommerce 2.6 Shipping Zones.
  4. *
  5. * @param array $rates Array of rates found for the package.
  6. * @return array
  7. */
  8. function my_hide_shipping_when_free_is_available( $rates ) {
  9. $free = array();
  10. foreach ( $rates as $rate_id => $rate ) {
  11. if ( 'free_shipping' === $rate->method_id ) {
  12. $free[ $rate_id ] = $rate;
  13. break;
  14. }
  15. }
  16. return ! empty( $free ) ? $free : $rates;
  17. }
  18. add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
Add Comment
Please, Sign In to add comment