Filter
uncanny-automator
automator_surecart_hydrate_common_tokens_v2
Filters SureCart common tokens during hydration, allowing modification of their values before use.
add_filter( 'automator_surecart_hydrate_common_tokens_v2', $callback, 10, 1 );
Description
Fires after SureCart account details are prepared for common tokens. Developers can modify the array of common SureCart tokens, such as `STORE_NAME` and `STORE_URL`, before they are used in automations. Ensure your modifications maintain the expected array structure.
Usage
add_filter( 'automator_surecart_hydrate_common_tokens_v2', 'your_function_name', 10, 1 );
Parameters
-
$output(mixed) - This parameter holds an array of common SureCart tokens, including the store's name and URL, which can be filtered before being returned.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the common SureCart tokens.
* This function adds a new token for the store's currency symbol.
*
* @param array $output The original array of common tokens.
* @return array The modified array of common tokens.
*/
add_filter( 'automator_surecart_hydrate_common_tokens_v2', function( $output ) {
// Ensure SureCartModelsAccount is available and can be instantiated.
if ( class_exists( 'SureCartModelsAccount' ) ) {
$account = SureCartModelsAccount::find();
// Check if an account was found and has a currency property.
if ( $account && isset( $account->currency ) ) {
// Add the new token for the store's currency symbol.
$output['STORE_CURRENCY_SYMBOL'] = $account->currency->symbol;
}
}
return $output;
}, 10, 1 );
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:533
public function hydrate_common_tokens() {
$account = SureCartModelsAccount::find();
$output = array(
'STORE_NAME' => $account->name,
'STORE_URL' => $account->url,
);
return apply_filters( 'automator_surecart_hydrate_common_tokens_v2', $output );
}