WPML
add_filter( 'wcml_custom_prices_fields_labels', 'the_callback_function', 10, 2 );
类型
filter
WooCommerce Multilingual 版本
3.8

说明

  • 向产品添加自定义价格字段标签。
  • 编辑/创建原始产品时,这些字段会显示在手动设置其他货币的价格部分中。
  • 要添加自定义价格字段,请参阅 wcml_custom_prices_fields 钩子。

参数

传递给此过滤器的参数有两个:
$labels
(array) 自定义价格字段标签数组。
$product_id
(integer) 原始产品的 ID。

使用示例

使用下面提供的示例代码,以获得以下屏幕截图中显示的结果。

自定义价格字段

示例
/*
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_custom_prices_fields',  'add_custom_price_fields', 10, 2 );
function add_custom_price_fields( $fields, $product_id ) {
    
    // Add a new custom price field 
    $fields[] = '_sign_up_fee'; 

    return $fields;

}


add_filter( 'wcml_custom_prices_fields_labels', 'set_labels_for_price_fields', 10, 2 );
function set_labels_for_price_fields( $labels, $product_id ){

    // Edit the label of a custom price field
    $labels[ '_sign_up_fee' ] = __( 'Sign-up Fee', 'woocommerce-multilingual' ); 

    return $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, wcml_multi_currency_ajax_actions

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