Push Registration to Hubspot (first_name and last_name )
-
Hello,
Push Registration to Hubspot
Below code is work but not work below two value: it will Null when save to Hubspot
‘firstname’ => get_user_meta($user_id, ‘first_name’, true),
‘lastname’ => get_user_meta($user_id, ‘last_name’, true),// Functions.php with a New Hook
WordPress themes have a file called functions.php, which runs automatically and therefore is a good place to put custom functions (but the warning about third-party themes bears repeating here). Near the end of the file, before the closing php tag (which looks like “?>), you need to insert a few lines of code:if (!function_exists('push_registration_to_hubspot')) { function push_registration_to_hubspot($user_id) { /* $hs_context stores analytics data about your visitor, including their HubSpot cookie, their IP address, and the page the form was on. If you have a custom registration page, you may want to replace the pageUrl and pageName arguments. */ $hs_context = array( 'hutk' => $_COOKIE['hubspotutk'], 'ipAddress' => $_SERVER['REMOTE_ADDR'], 'pageUrl' => site_url('/wp-login.php?action=register'), 'pageName' => 'WordPress User Registration' ); /* The key on the left here will contain the HubSpot property name, while the part on the right will pull the meta field from their WordPress profile. If you have more fields, this is where you'd add them. */ $fields = array( 'firstname' => get_user_meta($user_id, 'first_name', true), 'lastname' => get_user_meta($user_id, 'last_name', true), 'email' => get_userdata($user_id)->user_email, 'hs_context' => json_encode($hs_context) ); /* This is the URL we'll be submitting to. Replace "YourPortalID" and "YourFormGUID" with the appropriate values from the previous step. */ $endpoint = "https://forms.hubspot.com/uploads/form/v2/YourPortalID/YourFormGUID"; $data = wp_remote_post($endpoint, array( 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ), 'body' => $fields )); } add_action('user_register', 'push_registration_to_hubspot', 10, 1); }
- The topic ‘Push Registration to Hubspot (first_name and last_name )’ is closed to new replies.