WC_REST_Products_V2_Controller::save_taxonomy_terms()protectedWC 1.0

Save taxonomy terms.

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

Хуков нет.

Возвращает

WC_Product.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->save_taxonomy_terms( $product, $terms, $taxonomy );
$product(WC_Product) (обязательный)
Product instance.
$terms(массив) (обязательный)
Terms data.
$taxonomy(строка)
Taxonomy name.
По умолчанию: 'cat'

Код WC_REST_Products_V2_Controller::save_taxonomy_terms() WC 8.7.0

protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) {
	$term_ids = wp_list_pluck( $terms, 'id' );

	if ( 'cat' === $taxonomy ) {
		$product->set_category_ids( $term_ids );
	} elseif ( 'tag' === $taxonomy ) {
		$product->set_tag_ids( $term_ids );
	}

	return $product;
}