WPML
apply_filters( 'wcml_raw_price_amount', integer/float $price, string $currency )
类型
filter
WooCommerce Multilingual 版本
3.5

说明

  • 将默认货币的原始价格转换为所选货币。
  • 此过滤器通常用于筛选产品/变体价格。
  • 它在前端可用。

此过滤器应用于产品和变体中用于价格的自定义字段(从数据库读取时):

  • _price
  • _regular_price
  • _sale_price
  • _min_variation_price
  • _min_variation_price_regular_price
  • _mix_variation_price_sale_price
  • _max_variation_price
  • _max_variation_price_regular_price
  • _max_variation_price_sale_price

参数

$price
(integer/float)(必填)默认货币的原始价格。
$currency
(string)(可选)您希望将价格转换成的货币代码,例如“USD”、“EUR”等。如果未设置此参数,将使用前端当前使用的货币。

使用示例

示例
/*
Assume: 
 * USD = the default currency
 * EUR = the second currency
 * 0.8 = the exchange rate USD / EUR 
*/ 

$price = 100; 
$currency = "EUR";
$new_price = apply_filters('wcml_raw_price_amount', $price, $currency);

echo $new_price; // Return 80 

wcml_custom_prices_fields_labels, wcml_is_cache_enabled_for_switching_currency, wcml_geolocation_get_user_country, wcml_user_store_strategy, wcml_rounded_price, wcml_currencies_without_cents, wcml_product_custom_prices, wcml_custom_prices_strings, wcml_switch_currency, wcml_custom_prices_fields

所有 24 个 多货币功能 钩子 →