Automattic\WooCommerce\Internal\EmailEditor\PersonalizationTags
CustomerTagsProvider::register_tags │ public │ WC 1.0
Register customer tags with the registry.
Method of the class: CustomerTagsProvider{}
No Hooks.
Returns
null. Nothing (null).
Usage
$CustomerTagsProvider = new CustomerTagsProvider();
$CustomerTagsProvider->register_tags( $registry ): void;
- $registry(Personalization_Tags_Registry) (required)
- The personalization tags registry.
CustomerTagsProvider::register_tags() CustomerTagsProvider::register tags code
WC 10.3.6
public function register_tags( Personalization_Tags_Registry $registry ): void {
$registry->register(
new Personalization_Tag(
__( 'Customer Email', 'woocommerce' ),
'woocommerce/customer-email',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['order'] ) ) {
return $context['order']->get_billing_email() ?? '';
}
return $context['recipient_email'] ?? '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
$registry->register(
new Personalization_Tag(
__( 'Customer First Name', 'woocommerce' ),
'woocommerce/customer-first-name',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['order'] ) ) {
return $context['order']->get_billing_first_name() ?? '';
} elseif ( isset( $context['wp_user'] ) ) {
return $context['wp_user']->first_name ?? '';
}
return '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
$registry->register(
new Personalization_Tag(
__( 'Customer Last Name', 'woocommerce' ),
'woocommerce/customer-last-name',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['order'] ) ) {
return $context['order']->get_billing_last_name() ?? '';
} elseif ( isset( $context['wp_user'] ) ) {
return $context['wp_user']->last_name ?? '';
}
return '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
$registry->register(
new Personalization_Tag(
__( 'Customer Full Name', 'woocommerce' ),
'woocommerce/customer-full-name',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['order'] ) ) {
return $context['order']->get_formatted_billing_full_name() ?? '';
} elseif ( isset( $context['wp_user'] ) ) {
$first_name = $context['wp_user']->first_name ?? '';
$last_name = $context['wp_user']->last_name ?? '';
return trim( "$first_name $last_name" );
}
return '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
$registry->register(
new Personalization_Tag(
__( 'Customer Username', 'woocommerce' ),
'woocommerce/customer-username',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['wp_user'] ) ) {
return stripslashes( $context['wp_user']->user_login ?? '' );
}
return '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
$registry->register(
new Personalization_Tag(
__( 'Customer Country', 'woocommerce' ),
'woocommerce/customer-country',
__( 'Customer', 'woocommerce' ),
function ( array $context ): string {
if ( isset( $context['order'] ) ) {
$country_code = $context['order']->get_billing_country();
return WC()->countries->countries[ $country_code ] ?? $country_code ?? '';
}
return '';
},
array(),
null,
array( Integration::EMAIL_POST_TYPE ),
)
);
}