Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Emails\Schema
EmailsSettingsSchema::get_personalization_tag_prefixes
Get all unique prefixes from registered personalization tags.
Extracts the prefix part (before the /) from all registered personalization tags. For example, from [woocommerce/customer-name] it extracts 'woocommerce'. Results are cached to avoid repeated processing.
Method of the class: EmailsSettingsSchema{}
No Hooks.
Returns
Array. Array of unique prefixes, escaped for use in regex patterns.
Usage
// private - for code of main (parent) class only $result = $this->get_personalization_tag_prefixes(): array;
EmailsSettingsSchema::get_personalization_tag_prefixes() EmailsSettingsSchema::get personalization tag prefixes code WC 10.4.3
private function get_personalization_tag_prefixes(): array {
if ( null === $this->personalization_tags_registry ) {
return array();
}
// Return cached prefixes if available.
if ( null !== $this->cached_prefixes ) {
return $this->cached_prefixes;
}
$prefixes = array();
$tags = $this->personalization_tags_registry->get_all();
foreach ( $tags as $tag ) {
$token = $tag->get_token(); // E.g., [woocommerce/customer-name].
// Extract the prefix from the token (the part before the /).
// Remove brackets and get the part before /.
if ( preg_match( '/^\[([^\/\]]+)\//', $token, $matches ) ) {
$prefixes[ $matches[1] ] = true; // Use array key to ensure uniqueness.
}
}
// Convert to array of values and cache.
$this->cached_prefixes = array_keys( $prefixes );
return $this->cached_prefixes;
}