1 <?php
2 3 4 5 6 7 8 9
10
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 14 15 16 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 36 37 38 39
40 function wc_attribute_taxonomy_name( $name ) {
41 return 'pa_' . wc_sanitize_taxonomy_name( $name );
42 }
43
44 45 46 47 48 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 70 71 72 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 86 87 88 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