I am about to set one shipping method cost to zero if products in cart costs more than 99.99 (incl. taxes), source code found here:
add_filter( 'woocommerce_package_rates', 'custom_shipping_costs_based_on_products_cost', 20, 2 );
function custom_shipping_costs_based_on_products_cost( $rates, $package ) {
$products_amount = WC()->cart->cart_contents_total;
$taxes_amount = WC()->cart->get_cart_contents_tax();
$total = $products_amount + $taxes_amount;
if ($total > 99.98) {
foreach( $rates as $rate_key => $rate ){
if( $rate->method_id == 'alg_wc_shipping:198'){
$rates[$rate_key]->cost = 0;
}
}
}
return $rates;
}
Code doesn’t work, unfortunatelly, and I can’t find out why. The part where I’m counting $total
works fine, it’s tested tested. Method ID is found in cart html code:
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_alg_wc_shipping198" value="alg_wc_shipping:198" class="shipping_method" checked="checked">
I also tried to remove condition and just change cost, also does nothing.