Filter uncanny-automator

automator_surecart_hydrate_billing_tokens_v2

Filters the billing tokens used for SureCart checkout, allowing modification before they are hydrated.

add_filter( 'automator_surecart_hydrate_billing_tokens_v2', $callback, 10, 2 );

Description

Fires after SureCart's billing tokens are initialized for a checkout. Developers can modify or add to the `$billing_tokens` array, such as injecting custom billing information, before they are used in automations. The `$checkout` object is also available for context.


Usage

add_filter( 'automator_surecart_hydrate_billing_tokens_v2', 'your_function_name', 10, 2 );

Parameters

$billing_tokens (mixed)
This parameter is an array that will contain the billing tokens to be hydrated.
$checkout (mixed)
This parameter contains an array of billing tokens, which are key-value pairs representing billing information.

Return Value

The filtered value.


Examples

add_filter( 'automator_surecart_hydrate_billing_tokens_v2', 'my_custom_automator_surecart_billing_tokens', 10, 2 );

/**
 * Example function to add custom billing tokens for SureCart integration.
 *
 * This function demonstrates how to hook into the 'automator_surecart_hydrate_billing_tokens_v2'
 * filter to add or modify billing-related tokens that can be used in automation workflows.
 *
 * @param array  $billing_tokens The existing billing tokens.
 * @param object $checkout       The SureCart checkout object containing billing information.
 * @return array The modified billing tokens array.
 */
function my_custom_automator_surecart_billing_tokens( $billing_tokens, $checkout ) {

	// Add a custom token for the customer's company name if available.
	// This assumes the $checkout object might have a 'company' property.
	if ( isset( $checkout->company ) && ! empty( $checkout->company ) ) {
		$billing_tokens['BILLING_COMPANY'] = $checkout->company;
	} else {
		// Provide a default if the company is not set.
		$billing_tokens['BILLING_COMPANY'] = __( 'N/A', 'your-text-domain' );
	}

	// You could also modify existing tokens if needed.
	// For example, to append a prefix to the billing name:
	// if ( isset( $billing_tokens['BILLING_NAME'] ) ) {
	// 	$billing_tokens['BILLING_NAME'] = 'Client: ' . $billing_tokens['BILLING_NAME'];
	// }

	// Return the updated array of billing tokens.
	return $billing_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:590

public function hydrate_billing_tokens( $checkout = null ) {

		if ( null === $checkout ) {
			return array();
		}

		$billing_tokens = array(
			'BILLING_NAME'  => empty( $checkout->name ) ? '' : $checkout->name,
			'BILLING_EMAIL' => empty( $checkout->email ) ? '' : $checkout->email,
			'BILLING_PHONE' => empty( $checkout->phone ) ? '' : $checkout->phone,
		);

		return apply_filters( 'automator_surecart_hydrate_billing_tokens_v2', $billing_tokens, $checkout );
	}


Scroll to Top