Convert an ACF price field to another currency in WordPress
To convert an ACF price field to another currency in WordPress, let WPCS read the field itself: [wpcs_price meta_value=property_price] takes the custom field property_price of the current post and shows it in the currency the visitor selected. When this does not work, the output is either empty or 0.00, and the cause is almost always the meta key or the format of the stored value. Below: the setup, how to find the real key, what each wrong output means, and what to do with repeaters, options pages and page builders.
Put meta_value on [wpcs_price], not on [wpcs]
WPCS has two separate shortcodes. [wpcs] draws the switcher; [wpcs_price] prints a price. meta_value is an attribute of the price shortcode: [wpcs meta_value=property_price] shows a switcher and nothing else, so the field never changes. Use both, each in its place:
<?php
// header.php of a child theme: the switcher
echo do_shortcode('[wpcs show_flags=1 txt_type="desc"]');
?>
And in the content, where the price goes: [wpcs_price meta_value=property_price]. The shortcode reads the field of the current post, takes it as an amount in your base currency and converts it with the current rate. For a field of another post, add its ID: [wpcs_price meta_value=property_price post_id=123]. Always give meta_value together with post_id: with post_id alone, the shortcode looks for a field named wpcs_price.
The amounts in the field must be in the base currency, the one selected on the Currencies tab (see how the base currency works). If the field holds your own amount for each currency instead, such as USD:15,EUR:20, add type=fixed, as described in fixed prices per currency.
Find the real meta key of the field
An ACF field has three identifiers, and only one of them works:
- Field Label, for example "Property price": the text editors see. Not a key.
- Field Name, for example
property_price: this is the meta key under which ACF saves the value. Use it inmeta_value. - Field Key, for example
field_5fb9732bdda1e: ACF's internal ID, stored in a second, hidden meta row_property_price. It holds no price.
Fields inside other ACF fields are saved under combined names. A sub field amount of the group pricing is stored as pricing_amount. Rows of the repeater prices are stored as prices_0_amount, prices_1_amount and so on, counted from 0, so [wpcs_price meta_value=prices_0_amount] prints the first row. Fields of an ACF options page and of taxonomy terms are not post meta at all; the shortcode cannot read them, and they are converted in PHP as shown below.
Themes and plugins that print prices through their own helper functions hide the key: the name of such a function, or the word passed to it, is not necessarily the meta key, and a function cannot be passed to the shortcode. To see what a post really stores, add this snippet for a moment, open the post while logged in as an administrator, and read the list under the content:
/*
* Temporary: list all custom fields of the current post under its content,
* for administrators only. Child theme functions.php or a code snippets
* plugin. Remove it when you have found the key.
*/
add_filter('the_content', function ($content) {
if (is_singular() && current_user_can('manage_options')) {
$meta = get_post_meta(get_the_ID());
$content .= '<pre>' . esc_html(print_r($meta, true)) . '</pre>';
}
return $content;
});
An entry like [property_price] => Array ( [0] => 250000 ) gives you both the key and the stored value. For an ACF field, the key without the underscore holds the value and the one with the underscore holds the field key. For a theme-specific walkthrough, see converting theme listing prices.
Why the converted ACF price shows nothing or 0.00
The plugin reads the stored text as a number from its first character and stops at the first character that is not part of a plain number. That explains every odd result:
| Stored in the field | Shown in the base currency, format 1,000.00 | Why |
|---|---|---|
| Nothing, or wrong key | Nothing | The value is empty; empty and 0 print no price |
250000 or 1250.50 | 250,000.00 / 1,250.50 | Correct |
$250,000 or € 250 | 0.00 | A symbol before the number reads as 0 |
250,000 | 250.00 | Reading stops at the comma |
1.250 (thousands with a dot) | 1.25 | The dot is read as the decimal point |
12,50 | 12.00 | A decimal comma ends the number |
So an empty output means the key is wrong or the field is empty for this post; 0.00 or a much too small amount means the key is right and the stored format is wrong. The fix is a field that can only hold a plain number: in ACF, use the Number field type for prices and put symbols and words such as "per month" around the shortcode, not into the field. Formatting, symbol and separators then come from the currency's settings in WPCS.
For posts where the price is empty on purpose, the wpcs_price_free_text filter sets the text that [wpcs_price] prints instead of nothing. It applies to every empty or zero price on the site:
/*
* WPCS: text shown by [wpcs_price] when the amount is empty or 0.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('wpcs_price_free_text', function ($text) {
return 'Price on request';
});
Templates, repeaters and options pages: convert in PHP
In a theme template, inside the loop, run the same shortcode: echo do_shortcode('[wpcs_price meta_value=property_price]');. For values you read with ACF functions, pass the number as value. This works for every repeater row:
<?php
// Child theme template: price list from the ACF repeater "prices"
// with the sub fields "label" and "amount" (amounts in the base currency).
if (have_rows('prices')) {
echo '<ul>';
while (have_rows('prices')) {
the_row();
$amount = (float) get_sub_field('amount');
echo '<li>' . esc_html(get_sub_field('label')) . ': '
. do_shortcode('[wpcs_price value=' . $amount . ']') . '</li>';
}
echo '</ul>';
}
// A field of an ACF options page:
$fee = (float) get_field('booking_fee', 'option');
echo do_shortcode('[wpcs_price value=' . $fee . ']');
// A field of a taxonomy term ($term_id is the ID of the term):
$from = (float) get_field('from_price', 'term_' . $term_id);
echo do_shortcode('[wpcs_price value=' . $from . ']');
?>
If an old text field already contains values like 250,000, clean them before converting: (float) str_replace(array(',', ' '), '', $raw) turns 250,000 into 250000. Prefer the shortcode over $WPCS->wpcs_exchange_value() for display: the shortcode adds the currency symbol, and only its output is redrawn for each visitor when I am using cache plugin on my site is enabled.
Page builders and dynamic fields
A dynamic tag that shows an ACF field in a page builder prints the value as stored; it does not pass through WPCS. Put the builder's shortcode element in that place instead, with [wpcs_price meta_value=property_price] in it. In single post templates and loop item templates, the current post is the one being displayed, so each card shows its own price.
Two things do not work: a shortcode typed into an ACF text field (the field returns its text as it is, unless the template runs it through do_shortcode()), and [wpcs_price] placed inside a cell or attribute of another plugin's shortcode or table that does not process shortcodes. In both cases the code appears as text. Move the price to a place that runs shortcodes, or print it in PHP.
Checklist
meta_valueis on[wpcs_price], with the ACF Field Name (or the combined name for group and repeater fields).- The field stores a plain number in the base currency:
250000or1250.50. - Outside the post's own page,
post_idis set together withmeta_value. - Options page and term fields are read with
get_field()and converted withdo_shortcode(). - The temporary meta listing snippet is removed.
If the field still shows nothing, open a topic on the WPCS support forum with the shortcode, the meta key and the value from the meta listing.