/*
 Theme Name: Litho Child
 Theme URI: https://litho.themezaa.com/
 Description: Child theme for Litho theme
 Version: 1.2
 Author: ThemeZaa
 Author URI: https://www.themezaa.com/
 Tested up to: 5.8
 Requires PHP: 7.3
 Tags: one-column, two-columns, three-columns, left-sidebar, right-sidebar, grid-layout, custom-background, custom-colors, flexible-header, custom-menu, editor-style, featured-images, post-formats, sticky-post, theme-options, threaded-comments, translation-ready, blog, e-commerce
 License: Themeforest Split Licence
 License URI: https://themeforest.net/licenses/
 Template: litho
 Text Domain: litho-child
*/

/**
 * @snippet       Disable Free Shipping if Cart has Shipping Class
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */
  
add_filter( 'woocommerce_package_rates', 'bbloomer_hide_free_shipping_for_shipping_class', 9999, 2 );
   
function bbloomer_hide_free_shipping_for_shipping_class( $rates, $package ) {
   $shipping_class_target = 102; // shipping class ID (see screenshot below)
   $in_cart = false;
   foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
      if ( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {
         $in_cart = true;
         break;
      } 
   }
   if ( $in_cart ) {
      unset( $rates['free_shipping:7'] ); // shipping method ID (see screenshot below)
   }
   return $rates;
}
