Filter uncanny-automator

automator_surecart_shipping_tokens_v2

Filters SureCart shipping tokens before they are used, allowing for customization and additions.

add_filter( 'automator_surecart_shipping_tokens_v2', $callback, 10, 1 );

Description

Fires after shipping tokens are prepared for SureCart. Developers can add, remove, or modify shipping-related tokens for use in automations. This hook is useful for integrating custom shipping data or logic.


Usage

add_filter( 'automator_surecart_shipping_tokens_v2', 'your_function_name', 10, 1 );

Parameters

$tokens (mixed)
This parameter contains an array of shipping-related tokens that can be used within the SureCart integration of the Uncanny Automator plugin.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to add a custom token to the automator_surecart_shipping_tokens_v2 filter.
 *
 * This example adds a new token called 'SHIPPING_COUNTRY_CODE' which will represent
 * the ISO 3166-1 alpha-2 country code for the shipping address.
 *
 * @param array $tokens An array of existing shipping tokens.
 * @return array The modified array of shipping tokens, including the new custom token.
 */
add_filter( 'automator_surecart_shipping_tokens_v2', function( $tokens ) {

    // Add a new token for the shipping country code.
    $tokens[] = array(
        'tokenId'   => 'SHIPPING_COUNTRY_CODE',
        'tokenName' => esc_html_x( 'Shipping country code', 'Surecart', 'uncanny-automator' ),
        'tokenType' => 'text',
    );

    // Return the modified tokens array.
    return $tokens;

}, 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:352

public function shipping_tokens() {

		$tokens = array(
			array(
				'tokenId'   => 'SHIPPING_COUNTRY',
				'tokenName' => esc_html_x( 'Shipping country', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_STATE',
				'tokenName' => esc_html_x( 'Shipping state', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_CITY',
				'tokenName' => esc_html_x( 'Shipping city', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_LINE_1',
				'tokenName' => esc_html_x( 'Shipping line 1', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_LINE_2',
				'tokenName' => esc_html_x( 'Shipping line 2', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_NAME',
				'tokenName' => esc_html_x( 'Shipping name', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
			array(
				'tokenId'   => 'SHIPPING_POSTCODE',
				'tokenName' => esc_html_x( 'Shipping postcode', 'Surecart', 'uncanny-automator' ),
				'tokenType' => 'text',
			),
		);

		return apply_filters( 'automator_surecart_shipping_tokens_v2', $tokens );
	}


Scroll to Top