Filter uncanny-automator-pro

automator_pro_woo_item_in_term_multi_item_separator

Filters the separator used for multiple items in a WooCommerce term for the Automator Pro integration.

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

Description

Filters the separator used when displaying multiple WooCommerce product terms in a concatenated string. Use this hook to change the default ', ' to a custom string, allowing for different list formatting in Uncanny Automator recipes.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Customizer for the WooCommerce product term separator in Uncanny Automator PRO.
 *
 * This filter allows you to change the separator used when displaying multiple
 * product terms associated with an order item. For example, if a product belongs
 * to both "T-Shirts" and "Apparel" categories, this filter controls how
 * "T-Shirts" and "Apparel" are displayed when used in an automator token.
 *
 * @param string $separator The current separator string.
 * @return string The new separator string.
 */
add_filter( 'automator_pro_woo_item_in_term_multi_item_separator', 'my_custom_automator_woo_term_separator', 10, 1 );

function my_custom_automator_woo_term_separator( $separator ) {
	// Change the default separator from ', ' to ' | '
	return ' | ';
}

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

uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2841

public function extract_product_details( $products, $key, $type = '' ) {
		$value     = array();
		$func_name = "get_$key";
		/** @var WC_Product $product */
		foreach ( $products as $product ) {
			if ( ! $product instanceof WC_Product ) {
				continue;
			}
			$value[] = $product->$func_name();
		}

		if ( 'permalink' === $type ) {
			foreach ( $value as $k => $v ) {
				$value[ $k ] = get_permalink( $v );
			}
		}

		if ( 'thumb_id' === $type ) {
			foreach ( $value as $k => $v ) {
				$value[ $k ] = get_post_thumbnail_id( $v );
			}
		}

		if ( 'thumb_url' === $type ) {
			foreach ( $value as $k => $v ) {
				$value[ $k ] = get_the_post_thumbnail_url( $v, 'full' );
			}
		}

		if ( 'categories' === $type ) {
			foreach ( $value as $k => $v ) {
				$categories = wc_get_product( $v )->get_category_ids();
				$vv         = '-';
				if ( ! empty( $categories ) ) {
					$category_names = array();
					foreach ( $categories as $category ) {
						$category_names[] = get_term_by( 'id', $category, 'product_cat' )->name;
					}
					if ( ! empty( $category_names ) ) {
						$value[ $k ] = join( ',', $category_names );
					} else {
						$value[ $k ] = $vv;
					}
				} else {
					$value[ $k ] = $vv;
				}
			}
		}

		if ( 'tags' === $type ) {
			foreach ( $value as $k => $v ) {
				$tags = wc_get_product( $v )->get_tag_ids();
				$vv   = '-';
				if ( ! empty( $tags ) ) {
					$tag_names = array();
					foreach ( $tags as $tag ) {
						$tag_names[] = get_term( $tag )->name;
					}
					if ( ! empty( $tag_names ) ) {
						$value[ $k ] = join( ',', $tag_names );
					} else {
						$value[ $k ] = $vv;
					}
				} else {
					$value[ $k ] = $vv;
				}
			}
		}

		return join( apply_filters( 'automator_pro_woo_item_in_term_multi_item_separator', ', ' ), $value );
	}

Scroll to Top