• Resolved alortiz3

    (@alortiz3)


    alortiz3

    Is there a way to sync UM fields with default WordPress/Woo fields?

    For example, on the registration form we have the usual Username, Password, etc that do sync automatically when a new member signs up. In addition we have billing details and shipping details which do not sync. We would like to be able to add those fields to the default UM registration form and then sync with WordPress/Woo.

Viewing 9 replies - 1 through 9 (of 9 total)
  • @alortiz3

    This code snippet will give you Woo meta_keys to choose from when designing your UM Forms. If there are any Woo fields missing you can add to the array.

    You can install this code snippet to your active theme’s functions.php file
    or use the “Code Snippets” plugin.

    https://wordpress.org/plugins/code-snippets/

    add_filter( 'um_predefined_fields_hook', 'custom_predefined_fields_hook_woo', 10, 1 );
    
    function custom_predefined_fields_hook_woo( $predefined_fields ) {
    
        $woo_meta_keys = array( 'billing_postcode', 'billing_city', 'billing_address_1', 'billing_address_2', 'billing_state', 'billing_country', 
                                'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address_2', 'shipping_state', 'shipping_country', 
                                'paying_customer', 'billing_first_name', 'billing_last_name', 'billing_company', 'billing_phone', 'billing_email', 
                                'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_phone' );
    
        foreach( $woo_meta_keys as $woo_meta_key ) {
    
            $title = __( 'Woo ' . ucwords( str_replace( '_', ' ', $woo_meta_key )), 'ultimate-member' );
    
            $predefined_fields[$woo_meta_key] = array(
                
                            'title'    => $title,
                            'metakey'  => $woo_meta_key,
                            'type'     => 'text',
                            'label'    => $title,
                            'required' => 0,
                            'public'   => 1,
                            'editable' => 1,
            );
        }
    
        return $predefined_fields;
    }
    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    THANK-YOUUUUU!

    @alortiz3

    You can remove the code snippet and install this plugin to get an added feature of User Account Page display and editing of Woo meta_keys.

    https://github.com/MissVeronica/um-woo-predefined-fields

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    Both the code and the plugin worked amazingly well. The only thing that is missing is that it does not show a drop down for both the Country and the State. The fields do show up but not the drop down content. Any chance you can activate that?

    @alortiz3

    Yes you are right these fields should be dropdowns.
    You can test current update where you have country dropdown implemented.
    Country list is taken from UM.
    I have to find the list of states from Woo.

    Thread Starter alortiz3

    (@alortiz3)

    alortiz3

    This is what I’m using, not sure if it might be of any help to you:

    /* Get country this state field is representing */
    $for_country = isset( $args['country'] ) ? $args['country'] : WC()->checkout->get_value( 'billing_state' === $key ? 'billing_country' : 'shipping_country' );
    $states      = WC()->countries->get_states( $for_country );
    $data_label = ! empty( $args['label'] ) ? 'data-label="' . esc_attr( $args['label'] ) . '"' : '';
    $field .= '<select name="billing_state" id="billing_state" class="form_state state_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_html__( 'Select an option&hellip;', 'woocommerce' ) ) . '"  data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . $data_label . '>
    <option value="">' . esc_html__( 'Select an option&hellip;', 'woocommerce' ) . '</option>';
    $states='{"CA":{"AB":"Alberta","BC":"British Columbia","MB":"Manitoba","NB":"New Brunswick","NL":"Newfoundland and Labrador","NT":"Northwest Territories","NS":"Nova Scotia","NU":"Nunavut","ON":"Ontario","PE":"Prince Edward Island","QC":"Quebec","SK":"Saskatchewan","YT":"Yukon Territory"},"MX":{"DF":"Ciudad de Mu00e9xico","JA":"Jalisco","NL":"Nuevo Leu00f3n","AG":"Aguascalientes","BC":"Baja California","BS":"Baja California Sur","CM":"Campeche","CS":"Chiapas","CH":"Chihuahua","CO":"Coahuila","CL":"Colima","DG":"Durango","GT":"Guanajuato","GR":"Guerrero","HG":"Hidalgo","MX":"Estado de Mu00e9xico","MI":"Michoacu00e1n","MO":"Morelos","NA":"Nayarit","OA":"Oaxaca","PU":"Puebla","QT":"Queru00e9taro","QR":"Quintana Roo","SL":"San Luis Potosu00ed","SI":"Sinaloa","SO":"Sonora","TB":"Tabasco","TM":"Tamaulipas","TL":"Tlaxcala","VE":"Veracruz","YU":"Yucatu00e1n","ZA":"Zacatecas"},"US":{"AL":"Alabama","AK":"Alaska","AZ":"Arizona","AR":"Arkansas","CA":"California","CO":"Colorado","CT":"Connecticut","DE":"Delaware","DC":"District Of Columbia","FL":"Florida","GA":"Georgia","HI":"Hawaii","ID":"Idaho","IL":"Illinois","IN":"Indiana","IA":"Iowa","KS":"Kansas","KY":"Kentucky","LA":"Louisiana","ME":"Maine","MD":"Maryland","MA":"Massachusetts","MI":"Michigan","MN":"Minnesota","MS":"Mississippi","MO":"Missouri","MT":"Montana","NE":"Nebraska","NV":"Nevada","NH":"New Hampshire","NJ":"New Jersey","NM":"New Mexico","NY":"New York","NC":"North Carolina","ND":"North Dakota","OH":"Ohio","OK":"Oklahoma","OR":"Oregon","PA":"Pennsylvania","RI":"Rhode Island","SC":"South Carolina","SD":"South Dakota","TN":"Tennessee","TX":"Texas","UT":"Utah","VT":"Vermont","VA":"Virginia","WA":"Washington","WV":"West Virginia","WI":"Wisconsin","WY":"Wyoming","AA":"Armed Forces (AA)","AE":"Armed Forces (AE)","AP":"Armed Forces (AP)"}}';
    	$states=json_decode($states);
    	
    					foreach ( $states as $ckey => $cvalues ) {
    		
    					foreach ( $cvalues as $skey => $value ) {
    					$field .= '<option class="listt state_'.$ckey.'" value="' . esc_attr( $skey ) . '" ' . selected( $value, $skey, false ) . '>' . esc_html( $value ) . '</option>';
    					}
    					}
    
    					$field .= '</select>';
    
    	$field .= "<script type='text/javascript'>  jQuery(function($){
       jQuery(document.body).on('change', 'select[name=billing_country]', function(){
       		jQuery('.listt').removeClass('state_listt');
            console.log('Country changed: '+jQuery(this).val());
    		var statecss= 'state_'+jQuery(this).val();
             console.log('Country changed: '+statecss);
             jQuery('.'+statecss).addClass('state_listt');
          
            // Here run your function or code
        });
    });
    </script>";
    }
    			echo $field;
    }
    

    @alortiz3

    Thanks.
    I will be using this UM builtin “Choices Callback Feature in UM 2.1+”

    https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1

    Plugin Support andrewshu

    (@andrewshu)

    Hi @alortiz3

    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 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sync UM Fields w/ WordPress Fields’ is closed to new replies.