Home › Forums › Plugin Support › Need to link three user meta fields
- This topic has 3 replies, 2 voices, and was last updated 10 years, 8 months ago by smithandjones.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
March 4, 2014 at 9:07 pm #4933March 5, 2014 at 11:24 pm #4938KhaledMember
Hello,
These codes might be helpful for you:add_action( 'user_meta_after_user_update', 'updateCurrency' ); function updateCurrency( $response ) { $userID = $response->ID; $currencySelect = get_user_meta( $userID, 'buyer_default_currency_select', true ); if ( empty( $currencySelect ) ) return; switch( $currencySelect ) { case 'pound' : update_user_meta( $userID, 'buyer_default_currency_code', 'GBP' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '£' ); break; case 'dollar' : update_user_meta( $userID, 'buyer_default_currency_code', 'USD' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '$' ); break; case 'euro' : update_user_meta( $userID, 'buyer_default_currency_code', 'Euro' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '€' ); break; } }
Assume value of buyer_default_currency_select are pound, dollar or euro.
Thanks.
March 6, 2014 at 7:00 pm #4941smithandjonesMemberPerfect!
Thanks Khaled
March 6, 2014 at 9:24 pm #4942smithandjonesMemberHi Khaled
Could I check one more point with this code please.
I used code based on your suggestion as follows;
add_action( 'user_meta_after_user_update', 'user_meta_after_user_update_function' ); function user_meta_after_user_update_function( $response ){ $userID = $response->ID; $BuyerCurrencySelect = get_user_meta( $userID, 'buyer_default_currency_select', true ); if ( empty( $BuyerCurrencySelect ) ) return; switch( $BuyerCurrencySelect ) { case 'British Pound Sterling (£)' : update_user_meta( $userID, 'buyer_default_currency_code', 'GBP' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '£' ); break; case 'US Dollar ($)' : update_user_meta( $userID, 'buyer_default_currency_code', 'USD' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '$' ); break; case 'Euro (€)' : update_user_meta( $userID, 'buyer_default_currency_code', 'EUR' ); update_user_meta( $userID, 'buyer_default_currency_symbol', '€' ); break; }
The code above works fine.
So I wanted to do the same for the seller profile. I used the following code within the same function;
$userID = $response->ID; $SellerCurrencySelect = get_user_meta( $userID, 'seller_listing_currency_select', true ); if ( empty( $SellerCurrencySelect ) ) return; switch( $SellerCurrencySelect ) { case 'British Pound Sterling (£)' : update_user_meta( $userID, 'seller_default_currency_code', 'GBP' ); update_user_meta( $userID, 'seller_default_currency_symbol', '£' ); break; case 'US Dollar ($)' : update_user_meta( $userID, 'seller_default_currency_code', 'USD' ); update_user_meta( $userID, 'seller_default_currency_symbol', '$' ); break; case 'Euro (€)' : update_user_meta( $userID, 'seller_default_currency_code', 'EUR' ); update_user_meta( $userID, 'seller_default_currency_symbol', '€' ); break; }
This second code did not work.
So I experimented and changed one line from;
$SellerCurrencySelect = get_user_meta( $userID, 'seller_listing_currency_select', true );
to;
$SellerCurrencySelect = get_user_meta( $userID, 'seller_listing_currency', true );
Have you any idea why the second use of the same function was failing until I removed the ‘select’ term? Both variables are select types.
Regards
Robert
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.