Filter
uncanny-automator
automator_surecart_shipping_tokens
Filters available SureCart shipping tokens for dynamic use in automations.
add_filter( 'automator_surecart_shipping_tokens', $callback, 10, 1 );
Description
Filters the available SureCart shipping tokens. Developers can add, remove, or modify shipping-related tokens for use in Uncanny Automator recipes, allowing for dynamic customization of automation workflows based on SureCart shipping information.
Usage
add_filter( 'automator_surecart_shipping_tokens', 'your_function_name', 10, 1 );
Parameters
-
$tokens(mixed) - This parameter contains an array of available shipping-related tokens for use with SureCart in Uncanny Automator.
Return Value
The filtered value.
Examples
<?php
/**
* Example function to add a custom shipping token to SureCart integration.
* This function hooks into the 'automator_surecart_shipping_tokens' filter
* to add a new token representing the shipping country.
*
* @param array $tokens The existing shipping tokens.
* @return array The modified shipping tokens with the new custom token.
*/
add_filter(
'automator_surecart_shipping_tokens',
function ( $tokens ) {
// Check if $tokens is an array to avoid errors.
if ( ! is_array( $tokens ) ) {
$tokens = array();
}
// Add a new token for the shipping country.
$tokens['SHIPPING_COUNTRY'] = array(
'name' => esc_html_x( 'Shipping country', 'Surecart', 'uncanny-automator' ),
);
// You could also conditionally remove existing tokens or modify their names.
// For example, to remove the shipping postcode token:
// unset( $tokens['SHIPPING_POSTCODE'] );
return $tokens;
},
10, // Priority: default 10
1 // Accepted args: only the $tokens parameter is passed.
);
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:208
src/integrations/surecart/tokens/surecart-tokens.php:232
public function shipping_tokens() {
$tokens = array(
'SHIPPING_COUNTRY' => array(
'name' => esc_html_x( 'Shipping country', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_STATE' => array(
'name' => esc_html_x( 'Shipping state', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_CITY' => array(
'name' => esc_html_x( 'Shipping city', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_LINE_1' => array(
'name' => esc_html_x( 'Shipping line 1', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_LINE_2' => array(
'name' => esc_html_x( 'Shipping line 2', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_NAME' => array(
'name' => esc_html_x( 'Shipping name', 'Surecart', 'uncanny-automator' ),
),
'SHIPPING_POSTCODE' => array(
'name' => esc_html_x( 'Shipping postcode', 'Surecart', 'uncanny-automator' ),
),
);
return apply_filters( 'automator_surecart_shipping_tokens', $tokens );
}