1 <?php
  2 /**
  3  * WooCommerce Attribute Functions
  4  *
  5  * @author      WooThemes
  6  * @category    Core
  7  * @package     WooCommerce/Functions
  8  * @version     2.1.0
  9  */
 10 
 11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 12 
 13 /**
 14  * Get attribute taxonomies.
 15  *
 16  * @return object
 17  */
 18 function wc_get_attribute_taxonomies() {
 19 
 20     $transient_name = 'wc_attribute_taxonomies';
 21 
 22     if ( false === ( $attribute_taxonomies = get_transient( $transient_name ) ) ) {
 23 
 24         global $wpdb;
 25 
 26         $attribute_taxonomies = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies" );
 27 
 28         set_transient( $transient_name, $attribute_taxonomies );
 29     }
 30 
 31     return apply_filters( 'woocommerce_attribute_taxonomies', $attribute_taxonomies );
 32 }
 33 
 34 /**
 35  * Get a product attributes name.
 36  *
 37  * @param mixed $name
 38  * @return string
 39  */
 40 function wc_attribute_taxonomy_name( $name ) {
 41     return 'pa_' . wc_sanitize_taxonomy_name( $name );
 42 }
 43 
 44 /**
 45  * Get a product attributes label.
 46  *
 47  * @param mixed $name
 48  * @return string
 49  */
 50 function wc_attribute_label( $name ) {
 51     global $wpdb;
 52 
 53     if ( taxonomy_is_product_attribute( $name ) ) {
 54         $name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
 55 
 56         $label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
 57 
 58         if ( ! $label ) {
 59             $label = ucfirst( $name );
 60         }
 61     } else {
 62         $label = $name;
 63     }
 64 
 65     return apply_filters( 'woocommerce_attribute_label', $label, $name );
 66 }
 67 
 68 /**
 69  * Get a product attributes orderby setting.
 70  *
 71  * @param mixed $name
 72  * @return string
 73  */
 74 function wc_attribute_orderby( $name ) {
 75     global $wpdb;
 76 
 77     $name = str_replace( 'pa_', '', sanitize_title( $name ) );
 78 
 79     $orderby = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_orderby FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
 80 
 81     return apply_filters( 'woocommerce_attribute_orderby', $orderby, $name );
 82 }
 83 
 84 /**
 85  * Get an array of product attribute taxonomies.
 86  *
 87  * @access public
 88  * @return array
 89  */
 90 function wc_get_attribute_taxonomy_names() {
 91     $taxonomy_names = array();
 92     $attribute_taxonomies = wc_get_attribute_taxonomies();
 93     if ( $attribute_taxonomies ) {
 94         foreach ( $attribute_taxonomies as $tax ) {
 95             $taxonomy_names[] = wc_attribute_taxonomy_name( $tax->attribute_name );
 96         }
 97     }
 98     return $taxonomy_names;
 99 }
100 
WooCommerce API documentation generated by ApiGen 2.8.0