\Groundhogg\Contact

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Contact

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

MethodReturnsDescription
get_email()stringReturns the contact’s email address.
get_first_name()stringReturns the contact’s first name.
get_last_name()stringReturns the contact’s last name.
get_full_name()stringReturns the contact’s full name (first + last).
get_id()intReturns the contact ID.
get_user_id()intReturns the linked WordPress user ID, or 0 if none.
get_userdata()WP_User|falseReturns the linked WP_User object, or false.
get_owner_id()intReturns the user ID of the assigned owner.
get_ownerdata()WP_User|falseReturns the WP_User object of the owner.
get_optin_status()intReturns the numeric opt-in status. Compare against Preferences constants.
get_phone_number()stringReturns the contact’s primary phone number.
get_mobile_number()stringReturns the contact’s mobile number.
get_ip_address()stringReturns the contact’s last known IP address.
get_time_zone()string|DateTimeZoneReturns the contact’s time zone.
get_date_created()string|DateTimeReturns the date the contact was created.
get_address()arrayReturns the contact’s address fields as an associative array.
get_company()stringReturns the contact’s company name.
get_job_title()stringReturns the contact’s job title.
get_age()int|falseReturns 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 )stringReturns the URL of the contact’s profile picture (Gravatar or custom).
is_marketable()boolReturns true if the contact’s opt-in status allows marketing emails to be sent. Filterable via groundhogg/contact/is_marketable.
is_deliverable()boolReturns true if the contact’s email is not marked as bounced, complained, spam, or blocked.
is_confirmed()boolReturns true if the contact has confirmed their email address.
apply_tag( $tag_id_or_array )boolApplies 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 )boolRemoves one or more tags from the contact.
has_tag( $tag_id_or_name )boolReturns true if the contact has all of the specified tags.
has_tags( $maybe_tags )boolAlias of has_tag().
change_marketing_preference( $preference )voidUpdates the contact’s opt-in status to a Preferences constant value.
unsubscribe()voidSets the contact’s opt-in status to Preferences::UNSUBSCRIBED.
change_owner( $owner_id )boolAssigns a new owner user to the contact.
set_gdpr_consent( $type = 'gdpr' )boolRecords GDPR consent for the contact.
set_marketing_consent()boolRecords marketing consent.
has_gdpr_consent( $type = 'gdpr' )boolReturns true if the contact has recorded GDPR consent.
set_terms_agreement()boolRecords that the contact agreed to the terms and conditions.
auto_link_account()boolSearches for a WordPress user with the same email and links the account if found.
extrapolate_location()boolAttempts 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.