Filter
uncanny-automator
automator_surecart_common_tokens
Filters SureCart common tokens, allowing modification of available tokens for automation actions.
add_filter( 'automator_surecart_common_tokens', $callback, 10, 1 );
Description
Filters the common tokens available for SureCart integrations. Developers can add, remove, or modify these tokens to customize the data available for SureCart automations. This hook fires when SureCart tokens are being initialized, allowing for dynamic token management before they are used in automations.
Usage
add_filter( 'automator_surecart_common_tokens', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of common SureCart tokens that can be used within the Uncanny Automator integration.
Return Value
The filtered value.
Examples
add_filter(
'automator_surecart_common_tokens',
function ( $tokens ) {
// Add a custom token for the current user's email if it's not already present.
if ( ! isset( $tokens['USER_EMAIL'] ) ) {
$tokens['USER_EMAIL'] = array(
'name' => esc_html__( 'Current User Email', 'your-text-domain' ),
'hydrate_with' => 'automator_surecart_hydrate_user_email',
);
}
return $tokens;
},
10,
1
);
/**
* Hydrates the 'USER_EMAIL' token.
*
* This is a placeholder function and would contain the actual logic
* to retrieve the current user's email address.
*
* @param string $token The token identifier.
* @param mixed $object The object context.
*
* @return string The user's email address.
*/
function automator_surecart_hydrate_user_email( $token, $object ) {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
return $current_user->user_email;
}
return ''; // Return empty string if the user is not logged in.
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/surecart/tokens/surecart-tokens.php:32
public function common_tokens() {
$tokens = array(
'STORE_NAME' => array(
'name' => esc_html_x( 'Store name', 'Surecart', 'uncanny-automator' ),
'hydrate_with' => array( $this, 'hydrate_common_tokens' ),
),
'STORE_URL' => array(
'name' => esc_html_x( 'Store URL', 'Surecart', 'uncanny-automator' ),
'hydrate_with' => array( $this, 'hydrate_common_tokens' ),
),
);
return apply_filters( 'automator_surecart_common_tokens', $tokens );
}