Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help desired: Adding more fields to sync with HubSpot #9

Open
elosha opened this issue Jun 12, 2023 · 1 comment
Open

Help desired: Adding more fields to sync with HubSpot #9

elosha opened this issue Jun 12, 2023 · 1 comment

Comments

@elosha
Copy link

elosha commented Jun 12, 2023

Hey,

thanks for offering this useful plugin.

I intend to update user metadata that has been stored by WP User Frontend (WPUF), which can be described as a community plugin with frontend editing and enhanced profile. I'm not using WooCommerce.

As I understood, the action wc_hub_hubspot_contact_properties is called as soon as an user registers, updates or logs in. It takes the parameters $properties, $user – great, sounds easy. I built my coude upon your example. But while standard WP fields are mapped successfully, the custom ones don't appear in Hubspot.

For a very easy example, I store the phone number of a user in its meta key phone. And I want to map it to the field phone at Hubspot.

My code is as follows – what did I miss? Please ignore handling of the address etc.

function unaberg_wpuf_hubspot_contact_props_filter( $properties, $user ) {

	$user_address = $user->get( 'address' );			// Retrieve annoying address array once only
	if( !empty( $user_address[ 'street_address2' ] ) )	// Append 2nd address line to first, if set
		$user_address[ 'street_address' ] .= ', ' . $user_address[ 'street_address2' ];
	
	// Map our Hubspot fields => WP/WPUF data
	$wpuf_properties = array(
		[ 'property' => 'company', 'value' => $user->get( 'company' ) ],
		[ 'property' => 'firstname', 'value' => $user->get( 'first_name' ) ],
		[ 'property' => 'lastname', 'value' => $user->get( 'last_name' ) ],
		[ 'property' => 'phone', 'value' => $user->get( 'phone' ) ],
		[ 'property' => 'email', 'value' => $user->user_email ],
		[ 'property' => 'adresse', 'value' => $user_address[ 'street_address' ] ],
		[ 'property' => 'city', 'value' => $user_address[ 'city_name' ] ],
		[ 'property' => 'zip', 'value' => $user_address[ 'zip' ] ],
		[ 'property' => 'country', 'value' => $user_address[ 'country_select' ] ],
		[ 'property' => 'industry', 'value' => $user->get( 'industry' ) ],
		[ 'property' => 'anzahl_mitarbeiter', 'value' => $user->get( 'employees' ) ],
		[ 'property' => 'beitrag_umweltschutz', 'value' => $user->get( 'plan' ) ],
	);

	// Extend mapping while overwriting WooCommerce defaults
	return array_merge( $properties, $wpuf_properties );
}

add_filter( 'wc_hub_hubspot_contact_properties', 'unaberg_wpuf_hubspot_contact_props_filter', 10, 2 );

Thank you for reading and your help.

@kerkness
Copy link
Owner

On first glance I don't see anything that stands out. You will want to verify two things.. 1) that the hubspot property does indeed have the correct internal name and 2) that $user->get( ... ) method does return your custom values. If both those are verified then it /should/ map the data.

To verify the hubspot internal name of the properties, in hubspot go to your Settings > Data Management > Properties then find the hubspot field, click "Edit" and check the internal names as in the example screenshot

image

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants