English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Conversions  >  Before Parse Snippet

apply_filters_ref_array( 'vikappointments_before_parse_conversion_snippet', bool $status, array &$lookup, mixed $order, object $conversion )

Fires before parsing the snippet included within the conversion code. 


Description

Trigger hook before parsing the placeholders contained within a snippet of a conversion/tracking code.

It is possible to use this hook to inject or change the attributes of the $lookup array.

Here's how to add support for a new placeholder:

$lookup['tax'] = 12.50;

And here's how to include that value within the JS snippet:

var taxAmount = {tax};

Parameters

$status

(bool)  True on success, false otherwise.

&$lookup

(array)  An array of placeholders.

$order

(array|object)  An array/object holding the order details.

$conversion

(object)  The object holding the details of the conversion code.


Example

This example adds support for a new {tax} placeholder, which will be replaced by the total tax amount of the order.

/**
 * Trigger hook before parsing the placeholders contained within a snippet of
 * a conversion/tracking code. It is possible to use this hook to inject or
 * change the attributes of the $lookup array.
 *
 * @param  boolean  $status      True on success, false otherwise.
 * @param  array    &$lookup     An array of placeholders.
 * @param  mixed    $order       An array/object holding the order details.
 * @param  object   $conversion  The conversion details.
 */
add_filter('vikappointments_before_parse_conversion_snippet', function($status, &$lookup, $order, $conversion)
{
    // search for taxes only if we have an order wrapper
    if ($order instanceof VAPOrderWrapper)
    {
        // register tax placeholder
        $lookup['tax'] = $order->totals->tax;
    }

    return $status;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-10-04
Helpful?