Logic Hop PHP

Quick Reference

Overview

Logic Hop provides a number of PHP methods which allow you to implement personalization directly in your WordPress templates.

Evaluate Conditions

Conditions can be evaluated with PHP for use in themes and plugins. Pass a condition slug or ID into the $logichop->get_condition() function. If the condition is met, true is returned, if it is not met, false is returned.

The following example returns true if the condition slug today-is-friday is met or returns false if it is not met.

global $logichop;

$result = $logichop->get_condition( 'today-is-friday' );

Note: On sites where caching is in use, conditions evaluated with PHP will be cached. To avoid caching you can use the PHP output buffering with Logic Tags – View our tutorial to see how it’s done.

Set Goals

Goals can be set with PHP for use in themes and plugins. Pass a goal slug or ID into the $logichop->set_goal() function. When the goal is set, true is returned. If there was a problem setting the goal, false is returned.

The following example sets the newsletter-signup goal for the current user:

global $logichop;

$result = $logichop->set_goal( 'newsletter-signup' );

Check if Goal is Completed

You can check if a goal has been completed. Pass a goal slug or ID into the $logichop->get_goal() function. If the goal has been completed, an integer representing how many times the goal has been completed will be returned. If the goal has not been completed, 0 is returned.

The following example checks if the newsletter-signup goal has been completed by the current user:

global $logichop;

$result = $logichop->get_goal( 'newsletter-signup' );

Accessing Data

Logic Hop data can be update and retrieved via PHP for use in templates or other integrations.

Update Data Value

global $logichop;
$logichop->set_data( 'LeadScore', 42 );

Return Data

global $logichop;
$logichop->get_data( 'LeadScore' );

Echo Data

global $logichop;
$logichop->echo_data( 'LeadScore' );

Note that custom variables must be prefixed with ‘Custom’ when accessing them through get_data or echo_data:

$logichop->set_data( 'MyVariable', $some_data ); // set custom data
$logichop->get_data( 'Custom.MyVariable' ); // access custom data

Nested Data Elements

For data elements that contain objects use a period to separate objects, such as:

$logichop->get_data( 'Location.RegionName' );

For data elements that are arrays use a colon, such as:

$logichop->get_data( 'Query:utm_campaign' );

View the list of Data Variables for more information.

Updating Geolocation

Logic Hop geolocation can be updated by providing an IPv4 or IPv6 IP address.

global $logichop;
$logichop->update_geolocation( '161.185.160.93' );
Yo ! Thanks for checking out Logic Hop!