Filter
uncanny-automator
automator_wholesale_suite_save_lead_tokens
Filters the arguments array before saving lead tokens for Wholesale Suite.
add_filter( 'automator_wholesale_suite_save_lead_tokens', $callback, 10, 1 );
Description
Fires when Wholesale Suite lead tokens are saved. Allows developers to modify the available lead tokens or prevent specific tokens from being saved. Primarily used to customize or extend the lead token options for automations triggered by Wholesale Suite lead creation events.
Usage
add_filter( 'automator_wholesale_suite_save_lead_tokens', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of strings representing trigger meta keys, specifically initialized with 'WSS_LEAD_CREATED', to be used when filtering lead-related tokens.
Return Value
The filtered value.
Examples
/**
* Add a custom token for lead creation with additional details.
*
* This filter allows developers to hook into the 'automator_wholesale_suite_save_lead_tokens'
* action and add or modify the available tokens when a lead is created by Wholesale Suite.
*
* @param array $tokens An array of default lead tokens.
* @param array $args An array containing trigger arguments and entry arguments.
* Expected keys: 'trigger_args' (lead data), 'entry_args' (trigger code).
* @return array Modified array of lead tokens.
*/
add_filter(
'automator_wholesale_suite_save_lead_tokens',
function( $tokens, $args ) {
// Check if the current trigger code is for lead creation and if it's an array
if ( isset( $args['entry_args']['code'] ) && is_array( $tokens ) && 'WSS_LEAD_CREATED' === $args['entry_args']['code'] ) {
// Assuming $args['trigger_args'] contains the lead object or ID.
// For realism, let's assume it contains the lead ID as the first element.
$lead_id = ! empty( $args['trigger_args'][0] ) ? absint( $args['trigger_args'][0] ) : 0;
if ( $lead_id ) {
// Fetch lead details from Wholesale Suite or your CRM system.
// This is a placeholder; you'd replace this with actual API calls or data retrieval.
$lead_data = array(
'lead_id' => $lead_id,
'first_name' => get_post_meta( $lead_id, '_first_name', true ), // Example metadata key
'last_name' => get_post_meta( $lead_id, '_last_name', true ), // Example metadata key
'email' => get_post_meta( $lead_id, '_email', true ), // Example metadata key
'company' => get_post_meta( $lead_id, '_company', true ), // Example metadata key
);
// Add custom tokens with dynamic data.
// The structure here is based on how Automator often handles dynamic tokens.
// The key is the token identifier, and the value can be a callable or a simple value.
$tokens['WSS_LEAD_FIRST_NAME'] = $lead_data['first_name'];
$tokens['WSS_LEAD_LAST_NAME'] = $lead_data['last_name'];
$tokens['WSS_LEAD_EMAIL'] = $lead_data['email'];
$tokens['WSS_LEAD_COMPANY'] = $lead_data['company'];
$tokens['WSS_LEAD_DETAILS'] = $lead_data; // Store the whole array if needed
}
}
// Always return the modified tokens array.
return $tokens;
},
10, // Priority
2 // Accepted args count
);
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:47
public function save_token_data( $args, $trigger ) {
if ( ! isset( $args['trigger_args'] ) || ! isset( $args['entry_args']['code'] ) ) {
return;
}
$trigger_meta_order_tokens = apply_filters(
'automator_wholesale_suite_save_order_tokens',
array( 'WSS_ORDER_RECEIVED' ),
$args
);
$trigger_meta_lead_tokens = apply_filters(
'automator_wholesale_suite_save_lead_tokens',
array( 'WSS_LEAD_CREATED' ),
$args
);
if ( in_array( $args['entry_args']['code'], $trigger_meta_order_tokens ) ) {
$order_id = $args['trigger_args'][0];
$trigger_log_entry = $args['trigger_entry'];
if ( ! empty( $order_id ) ) {
Automator()->db->token->save( 'order_id', $order_id, $trigger_log_entry );
}
}
if ( in_array( $args['entry_args']['code'], $trigger_meta_lead_tokens ) ) {
$new_lead = $args['trigger_args'][0];
$trigger_log_entry = $args['trigger_entry'];
if ( is_object( $new_lead ) ) {
Automator()->db->token->save( 'lead_id', $new_lead->ID, $trigger_log_entry );
}
}
}