WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::update_terms() protected WC 3.0.0

For all stored terms in all taxonomies, save them to the DB.

{} It's a method of the class: WC_Product_Data_Store_CPT{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->update_terms( $product, $force );
$product(WC_Product) (required) (passed by reference — &)
Product object.
$force(true|false)
Force update. Used during create.
Default: false

Changelog

Since 3.0.0 Introduced.

Code of WC_Product_Data_Store_CPT::update_terms() WC 5.6.0

protected function update_terms( &$product, $force = false ) {
	$changes = $product->get_changes();

	if ( $force || array_key_exists( 'category_ids', $changes ) ) {
		$categories = $product->get_category_ids( 'edit' );

		if ( empty( $categories ) && get_option( 'default_product_cat', 0 ) ) {
			$categories = array( get_option( 'default_product_cat', 0 ) );
		}

		wp_set_post_terms( $product->get_id(), $categories, 'product_cat', false );
	}
	if ( $force || array_key_exists( 'tag_ids', $changes ) ) {
		wp_set_post_terms( $product->get_id(), $product->get_tag_ids( 'edit' ), 'product_tag', false );
	}
	if ( $force || array_key_exists( 'shipping_class_id', $changes ) ) {
		wp_set_post_terms( $product->get_id(), array( $product->get_shipping_class_id( 'edit' ) ), 'product_shipping_class', false );
	}

	_wc_recount_terms_by_product( $product->get_id() );
}