Woocommerce free shipping coupon not working if unset(Hide) free shipping method
-
I want to hide free shipping options and its working fine but free shipping coupon not working.
function hide_shipping_when_free_is_available($rates) { // Current value of the shopping cart $cart_subtotal = WC()->cart->subtotal; $currency = get_woocommerce_currency(); $free = array(); foreach ($rates as $rate_id => $rate) { if ('free_shipping' !== $rate->method_id) { $rates[$rate_id]->cost = $rates[$rate_id]->cost; } else if ('free_shipping' === $rate->method_id) { // Free shipping currency convert to euro and apply //if ($currency != 'USD' && $currency != 'GBP' && $currency != 'CHF') { $free_shipping_amounts = get_free_shipping_amounts(); $min = min((array)$free_shipping_amounts); if ($currency != 'USD' && $currency != 'GBP' && $currency != 'CHF') { $min = get_exchanged_currency($currency, $min, '', '', '', '', 0); } $free_shipping = new \WC_Shipping_Free_Shipping($rate->instance_id); $applied_coupons = WC()->cart->get_applied_coupons(); if ('either' === $free_shipping->requires && !empty($applied_coupons) && $cart_subtotal < $min) { foreach ($applied_coupons as $coupon_code) { $coupon = new WC_Coupon($coupon_code); if ($coupon->get_free_shipping()) { $coupon_free_ship = true; break; } } } if ($cart_subtotal < $min && !isset($coupon_free_ship)) { unset($rates[$rate_id]); echo "Hello"; } else { if ($currency == 'CHF') { unset($rates[$rate_id]); return $rates; } $free[$rate_id] = $rate; break; } } } return !empty($free) ? $free : $rates; } add_filter('woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100); The above code is working fine but I just want to hide free shipping methods. I tried to unset free shipping methods to hide it but free-shipping coupon code not working. coupon code applied but discount not applied. I appreciate it if someone can help me with this.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Woocommerce free shipping coupon not working if unset(Hide) free shipping method’ is closed to new replies.