Filter
uncanny-automator
automator_surecart_product_tokens_v2
Filters SureCart product tokens, allowing modification before they are used in Automator.
add_filter( 'automator_surecart_product_tokens_v2', $callback, 10, 1 );
Description
Filters the available SureCart product tokens for use in automations. Developers can add, remove, or modify tokens to customize how SureCart data is accessed and utilized within the Uncanny Automator plugin's token system, particularly for newer framework integrations.
Usage
add_filter( 'automator_surecart_product_tokens_v2', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of available tokens for SureCart products.
Return Value
The filtered value.
Examples
/**
* Example of how to add a custom token for SureCart products using the
* automator_surecart_product_tokens_v2 filter.
*
* This example adds a token for the product's SKU.
*/
add_filter( 'automator_surecart_product_tokens_v2', 'my_custom_surecart_product_tokens', 10, 1 );
/**
* Adds a custom SKU token to the SureCart product tokens.
*
* @param array $tokens The existing array of SureCart product tokens.
* @return array The modified array of SureCart product tokens including the new SKU token.
*/
function my_custom_surecart_product_tokens( $tokens ) {
// We'll assume we can get the SKU from the product object.
// In a real-world scenario, you'd likely have access to the product object
// or a way to retrieve it within the context of where these tokens are generated.
// For this example, we'll just hardcode a placeholder structure.
$new_sku_token = array(
'tokenId' => 'PRODUCT_SKU',
'tokenName' => esc_html__( 'Product SKU', 'my-text-domain' ),
'tokenType' => 'text',
// In a more advanced scenario, you might include a callback here
// to dynamically retrieve the SKU if the token is used.
// 'callback' => 'my_get_product_sku_callback',
);
// Add the new token to the existing array.
$tokens[] = $new_sku_token;
return $tokens;
}
/*
// Example of a hypothetical callback function if needed
function my_get_product_sku_callback( $args ) {
// $args would likely contain information about the specific order item
// or product that triggered the token.
// You would then fetch the SKU from that data.
// For demonstration purposes:
return 'EXAMPLE-SKU-123';
}
*/
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:212
src/integrations/surecart/tokens/surecart-tokens-new-framework.php:304
array(
'tokenId' => 'ORDER_COUPON',
'tokenName' => esc_html_x( 'Coupon code', 'Surecart', 'uncanny-automator' ),
'tokenType' => 'text',
),
);
return apply_filters( 'automator_surecart_product_tokens_v2', $tokens );
}
/**
*
* @return array[] The list of tokens where array key is the token identifier.
*/
public function order_tokens() {