WC_Brands::duplicate_add_product_brand_terms()publicWC 9.4.0

After product was added check if there are temporary brands and add them officially and remove the temporary brands.

Method of the class: WC_Brands{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Brands = new WC_Brands();
$WC_Brands->duplicate_add_product_brand_terms( $product_id );
$product_id(int) (required)
-

Changelog

Since 9.4.0 Introduced.

WC_Brands::duplicate_add_product_brand_terms() code WC 9.5.1

public function duplicate_add_product_brand_terms( $product_id ) {
	$product = wc_get_product( $product_id );
	// Bail if product isn't found.
	if ( ! $product instanceof WC_Product ) {
		return;
	}
	$term_ids = $product->get_meta( 'duplicate_temp_brand_ids' );
	if ( empty( $term_ids ) ) {
		return;
	}
	$term_taxonomy_ids = wp_set_object_terms( $product_id, $term_ids, 'product_brand' );
	$product->delete_meta_data( 'duplicate_temp_brand_ids' );
	$product->save();
}