Before I display ACF field, I want to manipulate it with my codes how to do this?
Are there any hooks documentation?
I want to manipulate my price field to display converted price on multiligual page. How do I do this?
since 1.2.5.2 you can
-
Improvement: Call function by using dynamic tag
{return=your_function('string', get_the_ID())}
give it a try, I use it to make automatic caption unit conversions in/cm cm/in and it works just as written
Can I use the Code Snippets plugin to call my function out on my ACF field.
Do I have to use it in the post edit screen?
The thing is, I have price saved in USD in ACF field, which I want to convert on other Multiligual pages by manipulating the field using hook.
Hi, thank you for your patience, yesterday was Thanksgiving here, kept me luckily away from my computer.
Regarding manipulating ACF fileds before displaying them, here a little example:
So you have a php function that does all the changes you are looking for such as,
and yes, it can absolutely be added at a snipped through code snippets :
function change_my_field($post_id ) {
// get ACF field value through the $post_id
$my_local_field=get_field(āthe_source_fieldā,$post_id);
// do all you have to do with it
$my_changed_field=$my_local_field*the_changes_I_want_to_operate_on_taht_field
//return it
return $my_changed_field;
}
Then within my page or template, within a text block (either parapraph or heading)
I would just call that function as follow:
{return=change_my_field(get_the_ID())}
and voila!
Do you think that would help with your project?
You still need now to get the the language of the page in order to get the correct currency but as I donāt know how you manage that information, hard to help on that partā¦
Best,
J
Sorry but I canāt set this function.
Here is what I have done.
An image with the show condition:
{return=change_my_field(get_current_user_id())}
An image with the show condition:
{return=change_my_field(get_current_user_id())}
The function:
function change_my_field( $user_id ) {
$my_local_field = true;
return $my_changed_field;
}
Normally, at lest one of the image must be displayed: but nothing is displayed!
Can you help me to find where the mistake is.
well the function returns $my_changed_field that isnāt set anywhere
try to return $my_local_field instead or set
$my_changed_field=$my_local_field;
Sorry, I made a bad copy of my function.
The function that I tested is:
function change_my_field($user_id ) {
$my_changed_field = true;
return $my_changed_field;
}
and nothing is displayed: neither āreturn=trueā nor āreturn=falseā
Great, it worked on the main language, but since Iām using WPML, it is not working in other languages why?
Just checked, as I never used functions in conditions before,
well, in the conditions, you donāt need to add {return=change_my_field()}
because you chose function return in the first select menu, you just need the name of your function and arguments in the next field
such as change_my_filed()
I just tried and it seems to work
You want to use the {return=my_function()} to evaluate a function within a textfield directly.
Hope that will help.
I never used WPML and I understand you are looking to change the currency, depending of the language of the post, right?
So you need to check the language of the current post and apply your change in currency accordingly.
Here, I found a basic example of such for WPML
So in your php snippet youāll have something like:
function My_Local_Currency($post_id){
//get the amount you want to convert
$amount_to_convert=get_field(āamountā,$post_id);
//get the language of current post
$post_language_information = apply_filters( āwpml_post_language_detailsā, NULL, $post_id );
$this_post_lang = $post_language_information[ālanguage_codeā];
//then apply the changes you want depending of the language
if($this_post_lang == āenā){
//do your currency conversion
$conversion_rate=3.2; }
elseif($this_post_lang==ādeā){
//do your currency conversion
$conversion_rate=0.2; }
//convert the amount
$my_converted_amount=$amount_to_convert*$convertion_rate;
//return the converted value
return $my_converted_amount;
}
Then you can just call that function in your Cwicly textfield where you need it to display using the technique we discribed earlier.
Hope that helps.
Super! Glad to help!