I follow this thread that works perfectly:
Set discount based on number of orders in WooCommerce.
But in my case I need to apply the discount not to the order total, but to the shipping cost and I would like to do this only for a specific country, specifically UK.
For example:
- ONLY First order: 6€ (flat rate shipping cost)
- From the second order onwards, always 25€ (flat rate shipping cost)
I already set the flat rate at 6€ for Uk, but I need to understand how to apply the 25€ surcharge only from the second order onwards.
This is my code attempt:
add_filter( 'woocommerce_package_rates', 'free_first_order_shipping', 20, 2 );
function free_first_order_shipping( $rates, $package ) {
if(is_user_logged_in()) {
$user_id = get_current_user_id();
//We want to know how many completed orders customer have or remove status if you dont care.
$args = array(
'customer_id' => 1,
'status' => array('wc-completed'),
);
$orders = wc_get_orders($args);
//If there are no orders returned apply free shipping
if($orders == 0) {
unset( $rates['flat_rate:15'] ); // Shipping 25 euro
}
else{
unset( $rates['betrs_shipping:10-2'] ); // Shipping 6 euro
}
}
return $rates;
}
However, this does not adjust the costs, but removes the shipping method. Any advice?