Home › Forums › Plugin Support › Need help to use action hook
- This topic has 7 replies, 2 voices, and was last updated 10 years, 9 months ago by smithandjones.
-
AuthorPosts
-
February 11, 2014 at 9:24 pm #4821February 16, 2014 at 10:49 am #4842smithandjonesMember
I haven’t had any reply so yesterday I spent a couple of hours experimenting which I guess is a good way to learn!
I got the following code to work, but with a couple of issues;
add_action( 'user_meta_after_user_update', 'user_meta_after_user_update_function' ); function user_meta_after_user_update_function( $response ){ extract( shortcode_atts( array( 'info' => 'buyer_default_currency_symbol', ), $atts ) ); $user_id = get_current_user_id(); $res = get_user_meta($user_id, $info, true); update_user_meta($user_id, 'wpcf-buyer-default-currency-symbol', $res); }
Here are the issues I need help with;
1. I don’t know how to extract checkbox type variables where you can have more than one value?
2. I have a problem with the ‘Country’ field. Although it displays the full country name in the drop down, e.g. ‘United Kingdom’, it actually returns the abbreviation,e.g. ‘UK’. I need to derive and display the full country name. How is this possible please?
Regards
Robert
February 16, 2014 at 3:30 pm #4843KhaledMemberHello Robert, Your post may be overlooked, sorry for that.
1. If you use get_user_meta to retrieve checkbox value, it will return an array with the corresponding value.
2. Go to User Meta >> Fields editor, expand your country field. There is a dropdown named “Save meta value by”,select country name and hit save.
Thanks.
February 17, 2014 at 10:03 am #4846smithandjonesMemberHi Khaled
Re point 2. Thank you, works fine.
Re point 1. I tried making a shortcode to allow the array to be displayed.
function payment_methods_func() { extract( shortcode_atts( array( 'info' => 'seller_payment_methods', ), $atts ) ); $user_id = get_current_user_id(); return $res = get_user_meta($user_id, $info, false); } add_shortcode( 'payment_methods', 'payment_methods_func' );
But when I use the shortcode, I get the word ‘Array’ displayed instead of the required values from the array.
I have tried the shortcode with a single string variable and it works fine.
Can you help please.
Regards
Robert
February 17, 2014 at 7:10 pm #4848KhaledMemberHello Robert,
You could use something like that:
function payment_methods_func() { extract( shortcode_atts( array( 'info' => 'seller_payment_methods', ), $atts ) ); $user_id = get_current_user_id(); $res = get_user_meta($user_id, $info, false); if ( is_array( $res ) ) return implode( ', ', $res ); return $res; } add_shortcode( 'payment_methods', 'payment_methods_func' );
implode( ‘, ‘, $res ) will separate array value by comma.
Thanks.
February 18, 2014 at 9:12 pm #4860smithandjonesMemberHello Khaled
I tried the code you suggested but it is still returning ‘ARRAY’. Could you look at the code again please.
Regards
Robert
February 20, 2014 at 12:48 am #4866KhaledMemberOh, sorry!
Please replace
$res = get_user_meta($user_id, $info, false);
with
$res = get_user_meta($user_id, $info, true);
Thanks.
February 20, 2014 at 5:58 pm #4872smithandjonesMemberHi Khaled. The latest code works perfectly.
Many thanks
Robert
-
AuthorPosts
- You must be logged in to reply to this topic.