availability:

WooCommerce Multilingual Version: 3.5

description:
  • Filter the IDs of variation’s taxonomies that a term belongs to.
  • Some WooCommerce extensions add their own custom variation product post types like WooCommerce Subscriptions. This filter is used in the function to check whether or not a product is variable. It collects all variation’s taxonomy IDs a term belongs to, for variable products.
type:
filter
category:
Miscellaneous
parameters:
add_filter( 'wcml_variation_term_taxonomy_ids', 'the_callback_function' );

There is only one parameter passed to this filter: term_taxonomy_ids.

$term_taxonomy_ids
(array) The array containing taxonomy term IDs of variable product types.
hook example usage:

Example

/**
 * This example is extracted from the WooCommerce Subscriptions compatibility class in the WCML code. 
 * This WooCommerce extension has its own variable product type called "variable-subscription"
 */

add_filter('wcml_variation_term_taxonomy_ids', 'add_wcml_variation_term_taxonomy_ids');

function add_wcml_variation_term_taxonomy_ids($get_variation_term_taxonomy_ids){
    global $wpdb;
    $get_variation_term_taxonomy_id = $wpdb->get_var("SELECT tt.term_taxonomy_id FROM $wpdb->terms AS t LEFT JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.slug = 'variable-subscription'");
    
    if(!empty($get_variation_term_taxonomy_id)){
        $get_variation_term_taxonomy_ids[] = $get_variation_term_taxonomy_id;    
    }
    
    return $get_variation_term_taxonomy_ids;
}