Advertisement
majeedraza

WooCommerce - Hide 2nd class if free shipping is available

Apr 15th, 2021
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement