WC_Product_Attribute::get_terms()
Gets terms from the stored options.
Method of the class: WC_Product_Attribute{}
No Hooks.
Return
Array|null
.
Usage
$WC_Product_Attribute = new WC_Product_Attribute(); $WC_Product_Attribute->get_terms();
WC_Product_Attribute::get_terms() WC Product Attribute::get terms code WC 9.7.1
public function get_terms() { if ( ! $this->is_taxonomy() || ! taxonomy_exists( $this->get_name() ) ) { return null; } $terms = array(); foreach ( $this->get_options() as $option ) { if ( is_int( $option ) ) { $term = get_term_by( 'id', $option, $this->get_name() ); } else { // Term names get escaped in WP. See sanitize_term_field. $term = get_term_by( 'name', $option, $this->get_name() ); if ( ! $term || is_wp_error( $term ) ) { $new_term = wp_insert_term( $option, $this->get_name() ); $term = is_wp_error( $new_term ) ? false : get_term_by( 'id', $new_term['term_id'], $this->get_name() ); } } if ( $term && ! is_wp_error( $term ) ) { $terms[] = $term; } } return $terms; }