Woocommerce override flat rate shipping
-
I working on a site that applies flat rate shipping to all orders. I would like to override the flat rate to $0 based on user and cart amount.
I found a code snippet from Byrce Adams that works, except for the conditional code I added — I’m hoping someone can access the code snippet below (added to functions.php) and advise how best to get it working:
// Free retail shipping
function adjust_shipping_rate( $rates ) {
// End if user is logged in
if ( is_user_logged_in() ) {
return;
} else {// Check guest shopper cart value before taxes
if ( $woocommerce->cart->subtotal_ex_tax >= 50 ) {// Loop through each rate
foreach ( $rates as $rate ) {// Store the previous cost in $cost
$cost = $rate->cost;// Adjust the cost as needed
$rate->cost = 0;}
return $rates;
}}}
add_filter( ‘woocommerce_package_rates’, ‘adjust_shipping_rate’, 50, 1 );
- The topic ‘Woocommerce override flat rate shipping’ is closed to new replies.