Show/hide shipping methods based on a WooCommerce checkout field value
问题 In WooCommerce, I have set different shipping methods , but one in particular must be exclusive for companies. For this I am using the following code: add_filter( 'woocommerce_package_rates', array( $this, 'package_rates' ), 10, 2 ); public function package_rates( $rates, $package ) { $company_rate_id = 'flat_rate:7'; if(!empty(WC()->customer->get_billing_company())){ $company_rates = $rates[ $company_rate_id ]; $rates = array( $company_rate_id => $company_rates ); }else{ unset( $rates[