Hi jenefer
this is how you retrieve user meta fields: https://codex.ww.wp.xz.cn/Function_Reference/get_user_meta
so you can try:
// get first the user field value you're interested in
$user_currency = get_user_meta( $user_id, 'currency', true );
// and then call wp_currencies function (example):
$rate = convert_currency( 1, $user_currency, 'USD' );
echo '1 ' . $user_currency . ' equals ' . $rate . ' USD;
In the example above it will echo the exchange rate of 1 USD converted to whichever $user_currency is. It also assumes your user meta field is called ‘currency’.
Note that you need to get the $user_id first. Is it a specific user? The logged in user? If it’s the current user (logged in user), it’s quite straightforward:
https://codex.ww.wp.xz.cn/Function_Reference/get_current_user_id
Hi Nekojira
Thanks for getting back to me so quickly. I am still struggling to adapt the code (its totally down to me not knowing php so appreciate any help I can get!).
I am trying to add the code on to my themes functions.php to use with a dynamically populated Gravity form field. The code I need for this is
add_filter(‘gform_field_value_your_parameter’, ‘my_custom_population_function’);
function my_custom_population_function($value){
return ‘HIDDEN FIELD VALUE’;
}
The person who is filling in the form is logged in and has the user currency field stored on their WP profile. So in the formula above I need to calculate the USD conversion rate and then feed this through to my hidden field.
Are you able to help? Every time I try I get an internal server error
Thanks
Jenefer