Using woocommerce, I managed to change the states to the counties here in Ireland, including the following code in the function.php
function wc_ie_counties_add_counties( $states ) {
$states['IE'] = array(
'Carlow' => 'Carlow',
'Cavan' => 'Cavan',
'Clare' => 'Clare',
'Cork' => 'Cork',
'Donegal' => 'Donegal',
'Dublin' => 'Dublin',
'Galway' => 'Galway',
'Kerry' => 'Kerry',
'Kildare' => 'Kildare',
'Kilkenny' => 'Kilkenny',
'Laois' => 'Laois',
'Leitrim' => 'Leitrim',
'Limerick' => 'Limerick',
'Longford' => 'Longford',
'Louth' => 'Louth',
'Mayo' => 'Mayo',
'Meath' => 'Meath',
'Monaghan' => 'Monaghan',
'Offaly' => 'Offaly',
'Roscommon' => 'Roscommon',
'Sligo' => 'Sligo',
'Tipperary' => 'Tipperary',
'Waterford' => 'Waterford',
'Westmeath' => 'Westmeath',
'Wexford' => 'Wexford',
'Wicklow' => 'Wicklow',
);
return $states;
}
add_filter( 'woocommerce_states', 'wc_ie_counties_add_counties' );
But I would like to remove a few counties if a specific product id is in the cart.
Example: If product id 581 and/or 590 is/are in the cart, display only Dublin, Cavan and Carlow states.
Thank you,
Using your actual code you need to set 2 arrays of states, one restricted and one completed. We will also need to check in cart items for product IDs 581 and/or 590. If one of this products is in cart we set the restricted array of states, if not we set the complete array of states.
The code:
Code goes in function.php file of the active child theme (or active theme).
It should works…
The same with Product Categories instead of Product IDs (based on author's code):
Code goes in function.php file of the active child theme (or active theme).
Now it should works for product variations (on variable products) too.