wc_attribute_taxonomy_id_by_name

Get a product attribute ID by name.

Description

(int) wc_attribute_taxonomy_id_by_name( (string) $name ); 

Returns (int)

Parameters (1)

0. $name (string)
Attribute name.

Usage

  1. if ( !function_exists( 'wc_attribute_taxonomy_id_by_name' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-attribute-functions.php'; 
  3.  
  4. // Attribute name. 
  5. $name = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_attribute_taxonomy_id_by_name($name); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-attribute-functions.php  
  1. function wc_attribute_taxonomy_id_by_name( $name ) { 
  2. $name = str_replace( 'pa_', '', wc_sanitize_taxonomy_name( $name ) ); 
  3. $taxonomies = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_id', 'attribute_name' ); 
  4.  
  5. return isset( $taxonomies[ $name ] ) ? (int) $taxonomies[ $name ] : 0;