iaffpro_custom_attribute_tag_category_taxonomy

Filter the taxonomy name for %category% custom attribute tag to extend it to categories of other post types. By default %category% fetches the category of the WordPress post post type.

The taxonomy name for the WordPress post‘s category is category and that of WooCommerce product category is product_cat.

Taxonomy Name Of WordPress Post Category Is Category
Taxonomy name of WordPress Post category is category.
Taxonomy Name Of WooCommerce Product Category Is Product_cat
Taxonomy name of WooCommerce Product Category is product_cat.
/**
 * Filter $category_taxonomy_name to extend %category% custom 
 * attribute tag to other post types. 
 * 
 * For example, if you have a custom post type named 'library' where 
 * the category taxnomy name is 'genre',
 you can return the 
 * category taxonomy name so that the name of the genre can be retrieved. 
 * 
 * Refer 3rd-party/woocommerce.php for example code.
 * 
 * @since 3.0
 * 
 * @param $category_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post where 
 * the image is used.
 */
$category_taxonomy_name = apply_filters( 'iaffpro_custom_attribute_tag_category_taxonomy', $category_taxonomy_name, $post_type );

Pro tip: This filter can be used for any taxonomy associated with a post type. Post category or WooCommerce product category is simply a name of a taxonomy.

Example Usage

The following code is from Image Attributes Pro version 3.0 and above where the filter is used to extend %category% to WooCommerce products.

/**
 * Add WooCommerce Product category taxonomy to custom attribute tag %category%.
 * 
 * @since 3.0
 * 
 * @param $category_taxonomy_name (string) Name of the taxonomy.
 * @param $post_type (string) will have the post type of the parent post 
 * where the image is used.
 * 
 * @return $category_taxonomy_name (string) WooCommerce product category 
 * taxonomy name ('product_cat') if $post_type is 'product'.
 */
function iaffpro_add_wc_product_category_to_custom_attribute_tag_category ( $category_taxonomy_name, $post_type ) {

	// Check if post type is WooCommerce product. 
	if ( strcmp( $post_type, 'product' ) === 0 ) {
		return 'product_cat';
	}

	return $category_taxonomy_name;
}

Related: iaffpro_custom_attribute_tag_tag_taxonomy