• Resolved jayme2604

    (@jayme2604)


    Dear @ultimate Member Support,

    I’m creating a form using Ultimate Member and all fields like “WC Billing Address, “WC Billing City and WC Billing Postcode” do automatically prefill which is good. However, this doesn’t work for “WC Billing Country”, it will be empty. As well if I would pick “Country” instead of “WC Billing Country”, it remains empty. Since it’s user meta data I would have expected to pick the country that’s selected in the user’s profile, but it doesn’t work like that apparently. Do I have to add some custom code / snippet to fill the field with the country value, or is there another easier solution?

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • @jayme2604

    this doesn’t work for “WC Billing Country”, it will be empty

    UM and WC are using different country setups.

    https://github.com/ultimatemember/ultimatemember/issues/980

    Yes you must use a code snippet for doing this country code to country name translation.

    Thread Starter jayme2604

    (@jayme2604)

    Thank you @missveronicatv.

    Can you help me with this code snippet please?

    add_action( 'um_registration_complete', 'um_021522_set_billing_country', 10, 2 ); function um_021522_set_billing_country( $user_id, $args ){ um_fetch_user( $user_id ); $country_codes = UM()->builtin()->get( 'countries' ); if( in_array( um_user( "country" ), $country_codes )) { update_user_meta( $user_id, "billing_country", array_search( um_user( "country" ), $country_codes )); } UM()->user()->remove_cache( $user_id ); }

    What does “um_021522…” mean? And I guess it would only work after a new registration, not for the current ones, right?

    @jayme2604

    Yes this code snippet was made for registration by UM updating the WC country code.

    Your issue is the opposite you want to only display and not update the WC registered country in an UM Profile Form?

    Thread Starter jayme2604

    (@jayme2604)

    Ah alright, precisely. These fields will be greyed out since the user will only be able to update their personal information from the account section. So, all I want to achieve is to display the country value (that’s already there basically) from the logged in user. It’s a new form created in Ultimate Member.

    • This reply was modified 1 year, 11 months ago by jayme2604.

    @jayme2604

    You can try to add this shortcode in your UM Profile Form like this:

    Billing country: [um_wc_billing_country]

    Add the code snippet to your active theme’s functions.php file
    or use the “Code Snippets” Plugin.

    add_shortcode( 'um_wc_billing_country', 'um_wc_billing_country_shortcode' );
    
    function um_wc_billing_country_shortcode( $atts, $content ) {
    
        if ( ! class_exists( "UM" ) ) return;
    
        um_fetch_user( um_profile_id() );
        $wc_billing_country = um_user( 'billing_country' );
    
        if( !empty( $wc_billing_country )) {
    
            $country_codes = UM()->builtin()->get( 'countries' ); 
            if( array_key_exists( $wc_billing_country, $country_codes )) {
                return $country_codes[$wc_billing_country];
            }
        }
        return;
    }

    https://www.ads-software.com/plugins/code-snippets/

    Thread Starter jayme2604

    (@jayme2604)

    Thank you @missveronicatv, that did the trick! One more ‘challenge’, how can I add this shortcode into a textbox field?

    Plugin Support andrewshu

    (@andrewshu)

    Hello @jayme2604

    In the profile form there is a “shortcode” field.

    Thank you.

    Plugin Support andrewshu

    (@andrewshu)

    Hi @jayme2604

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Value of WC Billing Country not returning’ is closed to new replies.