Filter
uncanny-automator
automator_wholesale_suite_validate_common_order_tokens
Filters Wholesale Suite order tokens before processing to allow validation or modification.
add_filter( 'automator_wholesale_suite_validate_common_order_tokens', $callback, 10, 1 );
Description
This filter allows developers to modify the list of available tokens for common Wholesale Suite order triggers. It fires after the default tokens are defined but before they are processed. Developers can add or remove token types from the returned array, controlling which order-related data is accessible for automations based on Wholesale Suite triggers like order received.
Usage
add_filter( 'automator_wholesale_suite_validate_common_order_tokens', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of token codes that need to be validated.
Return Value
The filtered value.
Examples
/**
* Filters the common order tokens for Wholesale Suite triggers to add custom validation.
*
* This function demonstrates how to extend the default list of order tokens
* that are considered valid for certain Wholesale Suite triggers.
*
* @param array $trigger_validations An array of default trigger codes to validate.
* @param array $args The arguments passed to the filter, including trigger meta.
*
* @return array The updated array of trigger codes to validate.
*/
function my_custom_wss_order_token_validation( $trigger_validations, $args ) {
// Assume we want to add validation for a hypothetical new Wholesale Suite trigger.
// For demonstration purposes, let's say there's a new trigger code 'WSS_ORDER_SHIPPED'.
// In a real scenario, you would check $args['triggers_meta']['code'] or other context
// to decide when to add your custom validation.
// If the current trigger code is one we want to apply custom validation to,
// add our new trigger code to the list.
// For this example, let's imagine we're always adding 'WSS_ORDER_SHIPPED'
// if the initial list contains 'WSS_ORDER_RECEIVED'.
if ( in_array( 'WSS_ORDER_RECEIVED', $trigger_validations, true ) ) {
$trigger_validations[] = 'WSS_ORDER_SHIPPED';
}
return $trigger_validations;
}
add_filter( 'automator_wholesale_suite_validate_common_order_tokens', 'my_custom_wss_order_token_validation', 10, 2 );
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/wholesale-suite/tokens/wss-tokens.php:79
* @param array $args
*
* @return array|array[]|mixed
*/
public function wss_order_tokens( $tokens = array(), $args = array() ) {
$trigger_code = $args['triggers_meta']['code'];
$trigger_validations = apply_filters(
'automator_wholesale_suite_validate_common_order_tokens',
array( 'WSS_ORDER_RECEIVED' ),
$args
);
if ( in_array( $trigger_code, $trigger_validations, true ) ) {
$possible_order_tokens = array(