lorro

WooCommerce - Hide 2nd class if free shipping is available

Apr 15th, 2021
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // WooCommerce - Hide 2nd class if free shipping is available
  3. add_filter( 'woocommerce_package_rates', 'custom_package_rates', 100 );
  4. function custom_package_rates( $rates ) {
  5.   $has_free = false;
  6.   foreach ( $rates as $rate_id => $rate ) {
  7.     // free must be first
  8.     if ( 'free_shipping' === $rate->method_id ) {
  9.       $has_free = true;
  10.     }
  11.     if ( $has_free & '2nd Class' == $rate->label ) {
  12.       unset( $rates[$rate_id] );
  13.     }
  14.   }
  15.   return $rates;
  16. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×