Logic Hop PHP

Quick Reference

Overview

Logic Hop provides a number of PHP functions 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 retrieved via PHP for use in templates or other integrations.

Echo Data

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

Return Data

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

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.