User Sync for Klaviyo Developer Information

Starting since version 1.1.0 of the plugin, we have added support for developers to customise and extend some of the features of the plugin.

Filters

Modify Profile Properties

usfk_modify_user_properties

Description

The filter usfk_modify_user_properties will allow you to modify and add additional user properties that will appear in Klaviyo.

Arguments

array $properties – the array of properties being added to the user profile
WP_User $user – the WP User object of the user being updated

Example

The below snippet shows how you can added an extra property called “locale” that is stored in a custom meta field “locale”. This filter is applied for both created and updated events.

function add_extra_user_properties_to_klaviyo($properties, $user)
{
    $properties["wordpress_locale"] = get_user_meta($user->ID, 'locale', true);
    
    return $properties;
}
add_filter('usfk_modify_user_properties', 'add_extra_user_properties_to_klaviyo', 10, 2);Code language: PHP (php)

Modify Event Properties

usfk_modify_event_properties

Description

The filter usfk_modify_event_properties will allow you to modify and add additional event properties that will appear in Klaviyo. This filter is applied for both created and updated events.

Arguments

array $properties – the array of properties being recorded in the event
WP_User $user – the WP User object of the user having the event recorded

Example

The below snippet shows how you can added an extra property called “welcome_message” to the user created/updated event.

function add_extra_event_properties_to_klaviyo($properties, $user)
{
    $properties['welcome_message'] = 'Hello ' . $user->first_name. ', welcome to my blog!';
    return $properties;
}

add_filter('usfk_modify_event_properties', 'add_extra_event_properties_to_klaviyo', 10, 2);Code language: PHP (php)

Manually trigger the Updated Profile Event

usfk_manually_call_update_profile

Description

There maybe occasions where you want to manually trigger the “WordPress – Updated User” event if you are updating WordPress Users programmatically or via a plugin.

You can programmatically execute the function to update the user and record an event in Klaviyo with this action.

Arguments

integer $user_id – The ID of the user you want to execute the action on
Example

The below snippet shows how you can update a user profile in Klaviyo after they have placed an order in Woocommerce that has changed status to “completed”


function update_klaviyo_user($user_id){
    do_action('usfk_manually_call_update_profile', $user_id);
}

add_action('woocommerce_payment_complete_order_status_completed', function ($order_id){
    $order = wc_get_order( $order_id );
    // Get the user ID from WC_Order methods
    $user_id = $order->get_user_id();
    update_klaviyo_user($user_id);
});Code language: PHP (php)

Manually trigger the Created Profile Event

usfk_manually_call_create_profile

Description

There maybe occasions where you want to manually trigger the “WordPress – Created User” event if you are updating WordPress Users programmatically or via a plugin.

You can programmatically execute the function to createthe user and record an event in Klaviyo with this action.

Arguments

integer $user_id – The ID of the user you want to execute the action on
Example

The below snippet shows how you can create a user profile in Klaviyo, where the User ID = 1

do_action('usfk_manually_call_update_profile', 1);Code language: JavaScript (javascript)