WC_GZD_Taxonomy

The Units Class stores units/measurements data.

Defined (1)

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

/includes/abstracts/abstract-wc-gzd-taxonomy.php  
  1. class WC_GZD_Taxonomy { 
  2.  
  3. private $taxonomy = ''; 
  4.  
  5. /** 
  6. * Adds the units from i18n template 
  7. */ 
  8. public function __construct( $taxonomy = '' ) { 
  9. $this->taxonomy = $taxonomy; 
  10.  
  11. /** 
  12. * Get units by key 
  13. * @param mixed $key 
  14. * @return mixed 
  15. */ 
  16. public function __get( $key ) { 
  17. return $this->get_term( $key ); 
  18.  
  19. public function get_term_object( $key, $by = 'slug' ) { 
  20.  
  21. do_action( 'woocommerce_gzd_get_term', $key, $by, $this->taxonomy ); 
  22.  
  23. $term = get_term_by( $by, $key, $this->taxonomy ); 
  24.  
  25. if ( ! $term || is_wp_error( $term ) ) 
  26. $term = false; 
  27.  
  28. do_action( 'woocommerce_gzd_after_get_term', $key, $by, $this->taxonomy ); 
  29.  
  30. return $term; 
  31.  
  32. public function get_term( $key, $by = 'slug' ) { 
  33. if ( $term = $this->get_term_object( $key, $by ) )  
  34. return $term->name; 
  35. return false; 
  36.  
  37. public function get_taxonomy() { 
  38. return $this->taxonomy; 
  39.  
  40. /** 
  41. * Returns mixed units array 
  42. * @return mixed units as array 
  43. */ 
  44. public function get_terms() { 
  45. $list = array(); 
  46. $terms = get_terms( $this->taxonomy, array( 'hide_empty' => false ) ); 
  47. if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { 
  48. foreach ( $terms as $term ) 
  49. $list[ $term->slug ] = $term->name; 
  50. return $list;