Code-Snippets-Functions/Execute a function on a child site/WooCommerce/change-product-price-based-on-customer-billing-country.txt

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;
}