Filter
uncanny-automator-pro
uap_option_all_wc_product_tags
Filters the array of all WooCommerce product tags available for selection within the plugin.
add_filter( 'uap_option_all_wc_product_tags', $callback, 10, 1 );
Description
This filter allows developers to modify the array of available tokens for WooCommerce product tags within Uncanny Automator. Developers can add, remove, or alter the 'Tag title', 'Tag ID', and 'Tag URL' tokens, providing custom data points for automations.
Usage
add_filter( 'uap_option_all_wc_product_tags', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example function to modify the data passed to the 'uap_option_all_wc_product_tags' filter.
* This example will conditionally add an extra token if the current user has a specific role.
*
* @param array $option The original option array containing token information.
* @return array The modified option array.
*/
function my_custom_uap_wc_product_tags_filter( $option ) {
// Check if the current user is logged in and has the 'administrator' role.
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
// If the user is an administrator, add an extra token for demonstration.
// In a real-world scenario, you might add a token related to administrator-specific actions or data.
$option['relevant_tokens']['extra_admin_tag_info'] = esc_html__( 'Admin Specific Tag Data', 'my-text-domain' );
}
// Always return the (potentially modified) option array.
return $option;
}
// Add the filter to WordPress.
// The priority is 10 (default) and it accepts 1 argument ($option).
add_filter( 'uap_option_all_wc_product_tags', 'my_custom_uap_wc_product_tags_filter', 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:852
public function all_wc_product_tags( $label = null, $option_code = 'WOOPRODTAG' ) {
if ( ! $label ) {
$label = esc_html_x( 'Tags', 'WooCommerce', 'uncanny-automator-pro' );
}
global $wpdb;
$tags = $wpdb->get_results(
$wpdb->prepare(
"SELECT terms.term_id,terms.name FROM $wpdb->terms as terms
LEFT JOIN $wpdb->term_taxonomy as rel ON (terms.term_id = rel.term_id)
WHERE rel.taxonomy = %s
ORDER BY terms.name",
'product_tag'
)
);
$options = array();
$options['-1'] = esc_html_x( 'Any tag', 'WooCommerce', 'uncanny-automator-pro' );
foreach ( $tags as $tag ) {
$title = $tag->name;
if ( empty( $title ) ) {
// translators: %1$s is the tag ID.
$title = sprintf( esc_html_x( 'ID: %1$s (no title)', 'WooCommerce', 'uncanny-automator-pro' ), $tag->term_id );
}
$options[ $tag->term_id ] = $title;
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_html_x( 'Tag title', 'WooCommerce', 'uncanny-automator-pro' ),
$option_code . '_ID' => esc_html_x( 'Tag ID', 'WooCommerce', 'uncanny-automator-pro' ),
$option_code . '_URL' => esc_html_x( 'Tag URL', 'WooCommerce', 'uncanny-automator-pro' ),
),
);
return apply_filters( 'uap_option_all_wc_product_tags', $option );
}