- availability:
-
WooCommerce Multilingual Version: 3.8
- description:
-
- Add additional custom price fields to products.
- These fields are displayed in the Set prices in other currencies manually section when editing/creating original products.
- To add custom price field labels, see the wcml_custom_prices_fields_labels hook.
- type:
- filter
- category:
- Multi-currency Feature
- parameters:
-
add_filter( 'wcml_custom_prices_fields', 'the_callback_function', 10, 2 );
There are two parameters passed to this filter:
- $fields
- (array) The custom price field array.
- $product_id
- (integer) The ID of an original product.
- hook example usage:
-
Use the example code provided below to get results shown in the following screenshot.
Example
1234567891011121314151617181920212223/*
* 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
;
}