automator_woo_multi_item_separator
Filters the separator used between multiple items in WooCommerce automations.
add_filter( 'automator_woo_multi_item_separator', $callback, 10, 1 );
Description
Filters the separator used when displaying multiple WooCommerce items in an Uncanny Automator recipe. Developers can modify this to change how lists of products, orders, or other WooCommerce data are presented, such as using a comma and space instead of ' | '.
Usage
add_filter( 'automator_woo_multi_item_separator', 'your_function_name', 10, 1 );
Parameters
-
$pieces(mixed) - This parameter represents the separator used to join multiple items when they are being displayed.
Return Value
The filtered value.
Examples
/**
* Modify the separator used for multiple WooCommerce items in an automator token.
*
* This filter allows customization of the string that separates multiple items
* when they are displayed as a single token value, for example, a list of products.
*
* @param string $separator The current separator string. Defaults to ' | '.
* @param array $pieces An array containing information about the token and its context.
* Expected to contain at least $pieces[2] which is the parsing object.
*
* @return string The modified separator string.
*/
add_filter( 'automator_woo_multi_item_separator', function( $separator, $pieces ) {
// Check if the parsing object is available and if it indicates a specific context
// where a different separator might be desired. For example, if we are dealing
// with a list of products being displayed in a specific shortcode context.
if ( isset( $pieces[2] ) && method_exists( $pieces[2], 'get_parsing_context' ) ) {
$context = $pieces[2]->get_parsing_context();
// If the context is specifically 'order_details_table', we might want a more
// readable, newline-based separator for better table formatting.
if ( 'order_details_table' === $context ) {
return "n"; // Use newline for better readability in tables.
}
}
// Otherwise, return the original separator or the modified one if logic above applied.
return $separator;
}, 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/woocommerce/tokens/wc-tokens.php:350
src/integrations/wholesale-suite/tokens/wss-tokens.php:241
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:1048
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:1543
if ( empty( $trigger_data ) || empty( $replace_args ) ) {
return $value;
}
$parse = $pieces[2];
$multi_line_separator = apply_filters( 'automator_woo_multi_item_separator', ' | ', $pieces );
foreach ( $trigger_data as $trigger ) {
if ( ! is_array( $trigger ) || empty( $trigger ) ) {
continue;
}
$trigger_id = $trigger['ID'];
$trigger_log_id = $replace_args['trigger_log_id'];