WC_REST_Products_V2_Controller::save_taxonomy_terms()protectedWC 1.0

Save taxonomy terms.

Method of the class: WC_REST_Products_V2_Controller{}

No Hooks.

Return

WC_Product.

Usage

// protected - for code of main (parent) or child class
$result = $this->save_taxonomy_terms( $product, $terms, $taxonomy );
$product(WC_Product) (required)
Product instance.
$terms(array) (required)
Terms data.
$taxonomy(string)
Taxonomy name.
Default: 'cat'

WC_REST_Products_V2_Controller::save_taxonomy_terms() code 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;
}