您需要使用woocommerce_get_price
过滤器:
add_filter(\'woocommerce_get_price\', \'return_custom_price\', $product, 2);
function return_custom_price($price, $product) {
global $post, $woocommerce;
// Array containing country codes
$county = array(\'CH\');
// Amount to increase by
$amount = 5;
// If the custromers shipping country is in the array
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ){
// Return the price plus the $amount
return $new_price = $price + $amount;
} else {
// Otherwise just return the normal price
return $price;
}
}
<小时>
EDIT:
要仅对一个产品执行此操作,您只需通过
$post
:
add_filter(\'woocommerce_get_price\', \'return_custom_price\', $product, 2);
function return_custom_price($price, $product) {
global $post, $woocommerce;
// Array containing country codes
$county = array(\'CH\');
// Get the post id
$post_id = $post->ID;
// Amount to increase by
$amount = 5;
// If the customers shipping country is in the array and the post id matches
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) && ( $post_id == \'12\' || $post_id == \'5\' || $post_id == \'6\' ) ){
// Return the price plus the $amount
return $new_price = $price + $amount;
} else {
// Otherwise just return the normal price
return $price;
}
}
只需将“12”替换为所需的产品ID。(“5”和“6”分别是结帐页)