Created
July 15, 2024 08:40
-
-
Save braddalton/026545cbef9fa3dfb52abd1defc4fed6 to your computer and use it in GitHub Desktop.
Free Shipping in WooCommerce https://wpsites.net/wordpress-tutorials/code-to-add-free-shipping-minimum-in-woocommerce/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_package_rates', 'custom_woocommerce_available_shipping_methods', 100); | |
function custom_woocommerce_available_shipping_methods($rates) { | |
$free_shipping_minimum = 100; // Set your minimum cart total for free shipping here | |
$cart_total = WC()->cart->get_subtotal(); | |
if ($cart_total >= $free_shipping_minimum) { | |
foreach ($rates as $rate_id => $rate) { | |
if ('free_shipping' === $rate->method_id) { | |
$free_shipping_rate = $rates[$rate_id]; | |
$rates = array($rate_id => $free_shipping_rate); | |
break; | |
} | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment