mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/77662926/change-product-price-based-on-customer-billing-country-in-woocommerce
15 lines
642 B
Text
15 lines
642 B
Text
add_filter('woocommerce_product_get_price', 'country_based_cart_item_price', 100, 2);
|
|
add_filter('woocommerce_product_variation_get_price', 'country_based_cart_item_price', 100, 2);
|
|
|
|
function country_based_cart_item_price( $price, $product ) {
|
|
// Define below in the array the desired country codes
|
|
$targeted_countries = array('US');
|
|
$billing_country = WC()->customer->get_billing_country();
|
|
|
|
// Only on cart and checkout pages
|
|
if ( ( is_checkout() || is_cart() ) && in_array($billing_country, $targeted_countries) ){
|
|
// Returns changed price
|
|
return $price / 260 * 1.25;
|
|
}
|
|
return $price;
|
|
}
|