How can I have a register form at home page for Marketpress users data?

Hi, how can I have a register for getting Marketpress users information? Name, city, address... What is the best way for that? Thank you!

  • Adam Czajczyk
    • Support Gorilla

    Hey diegpl,

    I hope you're having a nice day and thank you for your question!

    I could use some more information here. Could you please elaborate a bit on this? Usually the workflow is like this:

    - browse products
    - add to cart
    - go to checkout
    - provide necessary information (or login/register)
    - pay

    I assume you'd like to change it slightly so could you please describe what you wish to achieve in more detailed way? Please advise!

    Thanks!

    Cheers,
    Adam

  • Predrag Dubajic
    • Support

    Hi @diegpl,

    User meta from MarketPress is being saved in database so you would basically need to save your custom registration fields as the same meta fields in order to make it work.

    This however goes a bit beyond my coding knowledge so I'm going to flag this thread for our second level support dev guys so they can assist you with this.

    Best regards,
    Predrag

  • Hoang Ngo
    • Code Slayer

    Hi @diegpl,

    I hope you are well today.

    MarketPress will store the billing & shipping data in the table _usermeta, with those keys mp_shipping_info & mp_billing_info

    For the data structure, here is an example
    array ( 'email' => '', 'name' => '', 'address1' => '', 'address2' => '', 'city' => '', 'state' => '', 'zip' => '', 'country' => '', 'phone' => '', )
    So when you saving data from your registration form, the data will have to be in that structure, and storing in the table _usermeta by the meta key which I posted above :slight_smile:

    If you have any additional issues, please let us know and we'll be happy to help.

    Best regards,
    Hoang

  • diegpl
    • Syntax Hero

    Hmm, probably that is the problem then. Gravity forms gets these information in a separated structure. Please, take a look at my screenshot and if you can, give me a tip about what I should do. There are some separated user meta, which I have used in the trying too, but I am thinking it was created before, by WooCommerce, when I was trying to use it...

  • diegpl
    • Syntax Hero

    Hmm, that user meta in a separated structure really seems to be from WooCommerce, because I have activate it and taken a look into user data and the ones I have registered as address was there. So, do you guys have any idea about how could I have gravity forms integrated with Marketpress for user registration or will I really need to use another plugin for that? Thank you!!!

  • Hoang Ngo
    • Code Slayer

    Hi @diegpl,

    I hope you are well today.

    I think we can build a function for sync the information when user signup to MarketPress address. You can use this code for start

    add_action( 'user_register', 'sync_username_to_marketpress' );
    function sync_username_to_marketpress( $user_id ) {
    	$billing = array(
    		'email'    => 'user_email (Please replace)',
    		'name'     => 'user_name (Please replace)',
    		'address1' => 'user_address (Please replace)',
    		'address2' => 'user_address2 (Please replace)',
    		'city'     => 'user_city (Please replace)',
    		'state'    => 'user_state (Please replace)',
    		'zip'      => 'user_zip (Please replace)',
    		'country'  => 'user_country (Please replace)',
    		'phone'    => 'user_phone (Please replace)',
    	);
    	update_user_meta( $user_id, 'mp_billing_info', $billing );
    
    	$shipping = array(
    		'email'    => 'user_email (Please replace)',
    		'name'     => 'user_name (Please replace)',
    		'address1' => 'user_address (Please replace)',
    		'address2' => 'user_address2 (Please replace)',
    		'city'     => 'user_city (Please replace)',
    		'state'    => 'user_state (Please replace)',
    		'zip'      => 'user_zip (Please replace)',
    		'country'  => 'user_country (Please replace)',
    		'phone'    => 'user_phone (Please replace)',
    	);
    	update_user_meta( $user_id, 'mp_shipping_info', $shipping );
    }

    Please make sure you replace the dummy values with real user input. For install the code, you can add the code to your theme functions.php or use mu-plugins

    If you have any additional issues, please let us know and we'll be happy to help.

    Best regards,
    Hoang

  • diegpl
    • Syntax Hero

    So, I should not use the user meta fields of Gravity Forms to do that right? Could you suggest me a plugin in which I could insert this code instead of functions.php file? Because I use wpms, so it is not all the sites that will run this code, and I don`t want to modify the file, I have a big network...
    And how can I know what are the not dummy values? Should I look into the code by myself or asking Gravity Forms team?
    Really, really thank you for this code, supporters like you make me proud of being part of WPMUDEV :smiley:

  • Adam Czajczyk
    • Support Gorilla

    Hey diegpl!

    The "dummy values" to be replaced are like this:

    'email'    => 'user_email (Please replace)',

    As far as I understand, the entire "user_email (Please replace)" string should be pulled from the database from the Gravity Forms fields. The workflow would the be:

    - user registers using your custom register form
    - the code is triggered that synchronize registration data with MarketPress

    Let me though flag @Hoang Ngo here to correct me if I'm wrong :slight_smile:

    Do you think I could insert the code through this plugin https://wordpress.org/plugins/code-snippets/ ? Have you ever tested it? Thank you!

    I haven't had a chance to use this plugin on a live site yet but it seems reasonable. I've tested it some time ago on single WordPress install and it worked fine. I think then you may give it a try :slight_smile:

    Cheers,
    Adam

  • diegpl
    • Syntax Hero

    Yeah, I know about the dummy value, the problem is that Gravity Forms support is very, very, very, very bad. I am their for almost one month with no tip of solution at all. I do not know the values I should insert there... any tip about how to discover it? Do you think the only way it looking for it in the files? :disappointed:

  • Adam Czajczyk
    • Support Gorilla

    Hey diegpl!

    Assuming that this screenshot shows the fields used by your Gravity Forms registration form you could use something like this to replace the dummy values:

    add_action( 'user_register', 'sync_username_to_marketpress' );
    function sync_username_to_marketpress( $user_id ) {
    	$billing = array(
    		'email'    => get_user_meta($user_id, 'billing_email', TRUE),
    
    /... the rest of the code follows the same principle .../

    The user meta names (keys) seems to be shown in the first column of the image, right under the "User Meta" label.

    Cheers,
    Adam

  • diegpl
    • Syntax Hero

    Hi my friend, really thank you for you code :wink:
    But I think you are mistaken, the first column refers to WooCommerce and Marketpress fields, the second one is from Gravity Forms inputs, but they are just with numbers as values...
    So, do you suggest me something else for discovering that dummy values? Thank you a lot!!!

  • Adam Czajczyk
    • Support Gorilla

    Hey diegpl!

    You might be right, I won't argue :slight_smile: The screenshot suggest that these refer to GF but it's just a screenshot :slight_smile:

    I'm sure I can come up with a way to retrieve those fields however would it be possible to take closer look at your setup (including the database)? I'd need to get a direct access to your server if you don't mind, so could you please send in:

    Subject: "Attn: Adam Czajczyk"

    - your site's WordPress admin login URL
    - admin login and password (may be a temporary account)
    - FTP credentials (hostname, username, password, port number if needed)
    - phpMyAdmin login url (or server management panel e.g cPanel login credentials)
    - any other relevant URLs and information
    - link back to this thread

    Please use our contact form here
    https://premium.wpmudev.org/contact/.
    Select "I have a different question" from the drop-down list.

    Please be sure to make a full backup of your entire site first!

    Cheers,
    Adam

  • diegpl
    • Syntax Hero

    Look at this function I did to insert a language field on user registration and update the database every time a site is created:

    add_action("gform_site_created", "add_entry_to_db", 10, 5);
    function add_entry_to_db($site_id, $user_id, $entry, $config, $password) {
    	if ( $entry['form_id'] == 2 ) {
    		update_blog_option( $site_id, 'wplang', $entry[13] );
    	} elseif ( $entry['form_id'] == 1 ) {
    		update_blog_option( $site_id, 'wplang', $entry[9] );
    	}
    }

    Everything was updated through numbers, so, I guess that is how it is needed to be done too :disappointed:

  • diegpl
    • Syntax Hero

    13 is the language form input of the form that is being used for logged in users and 9 is the language form input used for not logged users form... so, probably the function needs to be done over inputs IDs that are here specially2.esites.pro, replacing dummy values, right? Thank you!

  • Adam Czajczyk
    • Support Gorilla

    Hey diegpl!

    I've received your e-mail and took a look around your setup.

    Thanks also for all the information you provided me with. I've conducted some further research and I think we're on a right track here with GF filters. Actually, it turns out that there's quite handy API that will most likely do the trick.

    Let me please run some trials and consult this with my colleagues developers and I'm sure we'll come up with some fine solution here!

    One last question: as I've mentioned before I do not have access on my test site to Gravity Forms with Registration add-on, so before I start let me know please how far I can go with "messing around" your site. Please advise!

    Surely having an access I'll backup everything so to be able to restore if anything goes wrong.

    Cheers,
    Adam

  • Hoang Ngo
    • Code Slayer

    Hi @diegpl,

    I updated the code here, for now, instead of binding the event to when an user registered. We will use the Gravity Form submission hook.

    add_action( 'gform_after_submission', 'sync_username_to_marketpress', 10, 2 );
    function sync_username_to_marketpress( $entry, $form ) {
    	$user_id = $entry['created_by'];
    
    	$first_name = rgar( $entry, '2.3' );
    	$last_name  = rgar( $entry, '2.6' );
    	$email      = rgar( $entry, '4' );
    	$phone      = rgar( $entry, '3' );
    	$address_1  = rgar( $entry, '1.1' );
    	$address_2  = rgar( $entry, '1.2' );
    	$city       = rgar( $entry, '1.3' );
    	$state      = rgar( $entry, '1.4' );
    	$zip        = rgar( $entry, '1.5' );
    
    	$billing = array(
    		'email'    => $email,
    		'name'     => $first_name . ' ' . $last_name,
    		'address1' => $address_1,
    		'address2' => $address_2,
    		'city'     => $city,
    		'state'    => $state,
    		'zip'      => $zip,
    		'country'  => '',
    		'phone'    => $phone,
    	);
    	update_user_meta( $user_id, 'mp_billing_info', $billing );
    
    	$shipping = array(
    		'email'    => $email,
    		'name'     => $first_name . ' ' . $last_name,
    		'address1' => $address_1,
    		'address2' => $address_2,
    		'city'     => $city,
    		'state'    => $state,
    		'zip'      => $zip,
    		'country'  => '',
    		'phone'    => $phone,
    	);
    	update_user_meta( $user_id, 'mp_shipping_info', $shipping );
    }

    Also, I prefer to implement custom code to your site via FTP rather than any WordPress plugin. As you know, a broken code can break your whole site, using FTP, you can quickly remove the code. If you use any WordPress plugin for that, you will have to disable the plugin first, and then go to database, find the record for broken code and manually remove it.

    Best regards,
    Hoang

  • Hoang Ngo
    • Code Slayer

    Hi @diegpl,

    I found that you inject the form to your page by raw HTML code, and I think that's the reason. Gravity form having a tool for inject the form by shortcode. Please check my screenshot.

    I also created a test page here http://specially2.***es.pro/test-register/, which it is working for MarketPress address field. I dumped the data after form submission, please check the screenshot too :slight_smile:

    Please note that, I'm using google translate when working on your site :slight_smile:

    Best regards,
    Hoang

  • diegpl
    • Syntax Hero

    Sorry my friend, but it seems that i just got your data and missed it, it did not update the user meta fields. These are your both users, which are not with the data:
    http://specially2.xxxx.pro/wp-admin/user-edit.php?user_id=266&wp_http_referer=%2Fwp-admin%2Fusers.php
    http://specially2.xxxx.pro/wp-admin/user-edit.php?user_id=268&wp_http_referer=%2Fwp-admin%2Fusers.php
    The code is not there too: http://xxxx.pro/wp-admin/network/theme-editor.php?file=functions.php&theme=pro3&scrollto=0
    I do not know if it is working on functions.php though, actually it did not work anywhere, even at header.php...
    Thank you!

  • Hoang Ngo
    • Code Slayer

    Hi @diegpl,

    For the code, I'm adding it inside the wp-content/mu-plugins/mp_sync.php . So when you add the function again, it will throw an error about function already exists :slight_smile:

    Also, I updated to code to

    add_action( 'gform_user_registered', 'sync_username_to_marketpress', 10,3);
    function sync_username_to_marketpress( $user_id,$entry,$entry) {
    	$first_name = rgar( $entry, '2.3' );
    	$last_name  = rgar( $entry, '2.6' );
    	$email      = rgar( $entry, '4' );
    	$phone      = rgar( $entry, '3' );
    	$address_1  = rgar( $entry, '1.1' );
    	$address_2  = rgar( $entry, '1.2' );
    	$city       = rgar( $entry, '1.3' );
    	$state      = rgar( $entry, '1.4' );
    	$zip        = rgar( $entry, '1.5' );
    
    	$billing = array(
    		'email'    => $email,
    		'name'     => $first_name . ' ' . $last_name,
    		'address1' => $address_1,
    		'address2' => $address_2,
    		'city'     => $city,
    		'state'    => $state,
    		'zip'      => $zip,
    		'country'  => '',
    		'phone'    => $phone,
    	);
    	update_user_meta( $user_id, 'mp_billing_info', $billing );
    
    	$shipping = array(
    		'email'    => $email,
    		'name'     => $first_name . ' ' . $last_name,
    		'address1' => $address_1,
    		'address2' => $address_2,
    		'city'     => $city,
    		'state'    => $state,
    		'zip'      => $zip,
    		'country'  => '',
    		'phone'    => $phone,
    	);
    	update_user_meta( $user_id, 'mp_shipping_info', $shipping );
    }

    It should works now, please check the account testtt1222 :slight_smile:

    Best regards,
    Hoang

  • diegpl
    • Syntax Hero

    You are the boss Hoang, your mom should be proud of you man!!! It works perfectly and I have learned a lot about Marketpress hooks and data. You really saved the day here! :wink:
    About Code Snippet plugin, it works very well, I have put the code there. If the code goes wrong you can just deactivate the snippet and edit it there, furthermore you can make it run just in the front end. Thank you a lot for everthing!!! I think we can close this thread now :wink:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.