extends Base_Object_With_Meta
Represents a single contact in the CRM. This is the primary object you will work with in any Groundhogg integration. It extends Base_Object_With_Meta so all meta, relationship, note, and CRUD methods are available in addition to the contact-specific methods listed here.
Methods
| Method | Returns | Description |
|---|---|---|
get_email() | string | Returns the contact’s email address. |
get_first_name() | string | Returns the contact’s first name. |
get_last_name() | string | Returns the contact’s last name. |
get_full_name() | string | Returns the contact’s full name (first + last). |
get_id() | int | Returns the contact ID. |
get_user_id() | int | Returns the linked WordPress user ID, or 0 if none. |
get_userdata() | WP_User|false | Returns the linked WP_User object, or false. |
get_owner_id() | int | Returns the user ID of the assigned owner. |
get_ownerdata() | WP_User|false | Returns the WP_User object of the owner. |
get_optin_status() | int | Returns the numeric opt-in status. Compare against Preferences constants. |
get_phone_number() | string | Returns the contact’s primary phone number. |
get_mobile_number() | string | Returns the contact’s mobile number. |
get_ip_address() | string | Returns the contact’s last known IP address. |
get_time_zone() | string|DateTimeZone | Returns the contact’s time zone. |
get_date_created() | string|DateTime | Returns the date the contact was created. |
get_address() | array | Returns the contact’s address fields as an associative array. |
get_company() | string | Returns the contact’s company name. |
get_job_title() | string | Returns the contact’s job title. |
get_age() | int|false | Returns the contact’s age in years calculated from their birthday meta, or false if not set. |
get_tag_ids() | int[] | Returns an array of tag IDs applied to this contact. |
get_tags( $as_object = false ) | int[]|Tag[] | Returns the contact’s tags. Pass true to get Tag objects instead of IDs. |
get_profile_picture( $size = 300 ) | string | Returns the URL of the contact’s profile picture (Gravatar or custom). |
is_marketable() | bool | Returns true if the contact’s opt-in status allows marketing emails to be sent. Filterable via groundhogg/contact/is_marketable. |
is_deliverable() | bool | Returns true if the contact’s email is not marked as bounced, complained, spam, or blocked. |
is_confirmed() | bool | Returns true if the contact has confirmed their email address. |
apply_tag( $tag_id_or_array ) | bool | Applies one or more tags to the contact. Accepts a tag ID, name, slug, Tag object, or array of any mix. Alias of add_tag(). |
remove_tag( $tag_id_or_array ) | bool | Removes one or more tags from the contact. |
has_tag( $tag_id_or_name ) | bool | Returns true if the contact has all of the specified tags. |
has_tags( $maybe_tags ) | bool | Alias of has_tag(). |
change_marketing_preference( $preference ) | void | Updates the contact’s opt-in status to a Preferences constant value. |
unsubscribe() | void | Sets the contact’s opt-in status to Preferences::UNSUBSCRIBED. |
change_owner( $owner_id ) | bool | Assigns a new owner user to the contact. |
set_gdpr_consent( $type = 'gdpr' ) | bool | Records GDPR consent for the contact. |
set_marketing_consent() | bool | Records marketing consent. |
has_gdpr_consent( $type = 'gdpr' ) | bool | Returns true if the contact has recorded GDPR consent. |
set_terms_agreement() | bool | Records that the contact agreed to the terms and conditions. |
auto_link_account() | bool | Searches for a WordPress user with the same email and links the account if found. |
extrapolate_location() | bool | Attempts to fill in location data from the contact’s IP address. |
Usage
Here’s a pseudo code example for a hypothetical post-purchase integration.
<?php
use Groundhogg\Preferences;
add_action( 'woocommerce_order_status_completed', 'my_plugin_handle_completed_order' );
/**
* Update contact data and apply tags when an order is completed.
*
* @param int $order_id
*
* @return void
*/
function my_plugin_handle_completed_order( $order_id ) {
$order = wc_get_order( $order_id );
$contact = \Groundhogg\get_contactdata( $order->get_billing_email() );
if ( ! $contact ) {
return;
}
// Only send to marketable contacts
if ( ! $contact->is_marketable() ) {
return;
}
// Update custom meta with the order details
$contact->update_meta( 'last_order_id', $order_id );
$contact->update_meta( 'last_order_total', $order->get_total() );
// Apply a tag to segment purchasers
$contact->apply_tag( 'customer' );
// Remove a prospect tag if present
$contact->remove_tag( 'prospect' );
// Queue a follow-up email
\Groundhogg\send_email_notification( MY_PLUGIN_THANK_YOU_EMAIL_ID, $contact );
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
