I´m workink with woocommerce, trying to develop a way to perform price calculation based in two factors : location of the customer by city and category.
I really stuck with this issue , i was able to change price based in the location of the customer , but if i try to filter by location and category does not work at the same time. To perform the filter by category i add this if statement.
if( has_term( array('nike'), 'product_cat' ,$product->ID) )
But sadly i really don´t understand why does not work.
Here´s the code
$userInfo = geoip_detect2_get_info_from_current_ip();
$countryCode = $userInfo->city->name;
switch ($countryCode) {
case 'Madrid':
if( has_term( array('nike'), 'product_cat' ,$product->ID) ) {
add_filter('woocommerce_get_price', 'product_custom_price', 10, 2);
function product_custom_price($price, $product) {
$custom_price = $product->get_regular_price();
return $custom_price * 1.5;}
}
break;
case 'Barcelona':
if( has_term( array('adidas'), 'product_cat' ,$product->ID) ) {
add_filter('woocommerce_get_price', 'product_custom_price', 10, 2);
function product_custom_price($price, $product) {
$custom_price = $product->get_regular_price();
return $custom_price * 1.25; }
}
break;
}
Aucun commentaire:
Enregistrer un commentaire