WC_Product_Attribute::get_slugs()publicWC 1.0

Gets slugs from the stored options, or just the string if text based.

Метод класса: WC_Product_Attribute{}

Хуков нет.

Возвращает

Массив.

Использование

$WC_Product_Attribute = new WC_Product_Attribute();
$WC_Product_Attribute->get_slugs();

Код WC_Product_Attribute::get_slugs() WC 8.7.0

public function get_slugs() {
	if ( ! $this->is_taxonomy() || ! taxonomy_exists( $this->get_name() ) ) {
		return $this->get_options();
	}
	$terms = array();
	foreach ( $this->get_options() as $option ) {
		if ( is_int( $option ) ) {
			$term = get_term_by( 'id', $option, $this->get_name() );
		} else {
			$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->slug;
		}
	}
	return $terms;
}