Filter
uncanny-automator
automator_surecart_common_tokens_v2
Filters SureCart common tokens before they are made available for use within the Automator.
add_filter( 'automator_surecart_common_tokens_v2', $callback, 10, 1 );
Description
Fires after common SureCart tokens are defined but before they are returned. Developers can use this filter to add, remove, or modify SureCart tokens for use in automations. This hook is essential for extending SureCart integration with custom token data.
Usage
add_filter( 'automator_surecart_common_tokens_v2', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of token definitions, where each token represents a piece of data that can be used in automations, such as the store's name or URL.
Return Value
The filtered value.
Examples
add_filter( 'automator_surecart_common_tokens_v2', 'my_custom_surecart_tokens', 10, 1 );
/**
* Adds a custom token for the current user's SureCart customer ID to the SureCart common tokens.
*
* This function demonstrates how to extend the existing SureCart tokens provided by Uncanny Automator
* with your own custom data, making it available for use in automations.
*
* @param array $tokens An array of existing SureCart tokens.
* @return array The modified array of SureCart tokens including the new custom token.
*/
function my_custom_surecart_tokens( $tokens ) {
// Check if the current user is logged in and has a SureCart customer ID associated.
// This is a hypothetical check; in a real scenario, you'd likely have a more robust way
// to retrieve the SureCart customer ID for the current user.
$user_id = get_current_user_id();
if ( $user_id ) {
$surecart_customer_id = get_user_meta( $user_id, 'surecart_customer_id', true ); // Replace with your actual meta key.
if ( ! empty( $surecart_customer_id ) ) {
$tokens[] = array(
'tokenId' => 'CURRENT_USER_SURECART_CUSTOMER_ID',
'tokenName' => esc_html_x( 'My SureCart Customer ID', 'Surecart', 'uncanny-automator' ),
'tokenType' => 'text', // Or 'number' if appropriate
);
}
}
return $tokens;
}
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-new-framework.php:34
public function common_tokens() {
$tokens = array(
array(
'tokenId' => 'STORE_NAME',
'tokenName' => esc_html_x( 'Store name', 'Surecart', 'uncanny-automator' ),
'tokenType' => 'text',
),
array(
'tokenId' => 'STORE_URL',
'tokenName' => esc_html_x( 'Store URL', 'Surecart', 'uncanny-automator' ),
'tokenType' => 'url',
),
);
return apply_filters( 'automator_surecart_common_tokens_v2', $tokens );
}