WooCommerce Code Reference

Personalization_Tag
in package

The class represents a personalization tag that contains all necessary information for replacing the tag with its value and displaying it in the UI.

Table of Contents

$attributes  : array<string|int, mixed>
The attributes which are used in the Personalization Tag UI.
$callback  : callable
The callback function which returns the value of the personalization tag.
$category  : string
The category of the personalization tag for categorization on the UI.
$name  : string
The name of the tag displayed in the UI.
$token  : string
The token which is used in HTML_Tag_Processor to replace the tag with its value.
$value_to_insert  : string
The value that is inserted via the UI. When the value is null the token is generated based on $token attribute and $attributes.
__construct()  : mixed
Personalization_Tag constructor.
execute_callback()  : string
Executes the callback function for the personalization tag.
get_attributes()  : array<string|int, mixed>
Returns the attributes of the personalization tag.
get_category()  : string
Returns the category of the personalization tag.
get_name()  : string
Returns the name of the personalization tag.
get_token()  : string
Returns the token of the personalization tag.
get_value_to_insert()  : string
Returns the token to insert via UI in the editor.

Properties

Methods

__construct()

Personalization_Tag constructor.

public __construct(string $name, string $token, string $category, callable $callback[, array<string|int, mixed> $attributes = array() ][, string|null $value_to_insert = null ]) : mixed

Example usage: $tag = new Personalization_Tag( 'First Name', 'user:first_name', 'User', function( $context, $args ) { return $context['user_firstname'] ?? 'user'; }, array( default => 'user' ), 'user:first default="user"' );

Parameters
$name : string

The name of the tag displayed in the UI.

$token : string

The token used in HTML_Tag_Processor to replace the tag with its value.

$category : string

The category of the personalization tag for categorization on the UI.

$callback : callable

The callback function which returns the value of the personalization tag.

$attributes : array<string|int, mixed> = array()

The attributes which are used in the Personalization Tag UI.

$value_to_insert : string|null = null

The value that is inserted via the UI. When the value is null the token is generated based on $token attribute and $attributes.

Return values
mixed

execute_callback()

Executes the callback function for the personalization tag.

public execute_callback(mixed $context[, array<string|int, mixed> $args = array() ]) : string
Parameters
$context : mixed

The context for the personalization tag.

$args : array<string|int, mixed> = array()

The additional arguments for the callback.

Return values
stringThe value of the personalization tag.