Filter
uncanny-automator-pro
uap_option_wc_taxonomies
Filters the WooCommerce taxonomies used for user roles and access, allowing customization of available product categories.
add_filter( 'uap_option_wc_taxonomies', $callback, 10, 1 );
Description
Filters the WooCommerce product taxonomy options array. Developers can modify the taxonomy options available for use in Uncanny Automator recipes, allowing for custom filtering or augmentation of the default product taxonomy selections.
Usage
add_filter( 'uap_option_wc_taxonomies', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example function to filter the uap_option_wc_taxonomies hook.
* This example adds a custom taxonomy to the list of available WooCommerce taxonomies
* that Uncanny Automator can use for triggers or actions.
*
* @param array $option The current array of taxonomy options.
* @return array The modified array of taxonomy options.
*/
add_filter( 'uap_option_wc_taxonomies', function( $option ) {
// Check if we are dealing with the expected structure.
// This is a basic check, more robust validation might be needed in a real scenario.
if ( ! isset( $option['relevant_tokens'] ) || ! is_array( $option['relevant_tokens'] ) ) {
return $option;
}
// Get all registered WooCommerce taxonomies.
$wc_taxonomies = Automator_Woocommerce_Pro_Helpers::get_wc_product_taxonomies();
// Add our custom taxonomy if it exists and is not already in the list.
// Let's assume 'product_brand' is a custom taxonomy we've registered elsewhere.
$custom_taxonomy_slug = 'product_brand';
$custom_taxonomy_label = esc_html__( 'Product Brand', 'my-text-domain' );
if ( array_key_exists( $custom_taxonomy_slug, $wc_taxonomies ) && ! array_key_exists( $custom_taxonomy_slug, $option['relevant_tokens'] ) ) {
$option['relevant_tokens'][ $custom_taxonomy_slug ] = $custom_taxonomy_label;
}
// You could also remove existing taxonomies if needed.
// For example, to remove the 'product_tag' taxonomy:
/*
if ( isset( $option['relevant_tokens']['product_tag'] ) ) {
unset( $option['relevant_tokens']['product_tag'] );
}
*/
return $option;
}, 10, 1 );
?>
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/helpers/woocommerce-pro-helpers.php:1841
public function wc_taxonomies( $label = null, $option_code = 'WC_TAXONOMIES', $args = array() ) {
if ( ! $label ) {
$label = esc_html_x( 'Taxonomy', 'Woocommerce', 'uncanny-automator-pro' );
}
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$pass_args = array(
'public' => true,
'object_type' => array( 'product' ),
);
$output = 'object';
$taxonomies = get_taxonomies( $pass_args, $output );
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) {
$options[ $taxonomy->name ] = esc_html( $taxonomy->labels->singular_name );
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'endpoint' => $end_point,
'relevant_tokens' => array(
$option_code => esc_html_x( 'Product taxonomy', 'Woocommerce', 'uncanny-automator-pro' ),
),
);
return apply_filters( 'uap_option_wc_taxonomies', $option );
}