WC_REST_Products_V1_Controller::save_taxonomy_terms()
Save taxonomy terms.
Method of the class: WC_REST_Products_V1_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_V1_Controller::save_taxonomy_terms() WC REST Products V1 Controller::save taxonomy terms code WC 9.8.1
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; }