WordPress at Your Fingertips
function is not described

WC_Post_Data::force_default_term() public WC 3.3.0

Ensure default category gets set.

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

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Post_Data::force_default_term( $object_id, $terms, $tt_ids, $taxonomy, $append );
$object_id(int) (required)
Product ID.
$terms(array) (required)
Terms array.
$tt_ids(array) (required)
Term ids array.
$taxonomy(string) (required)
Taxonomy name.
$append(true|false) (required)
Are we appending or setting terms.

Changelog

Since 3.3.0 Introduced.

Code of WC_Post_Data::force_default_term() WC 5.7.1

public static function force_default_term( $object_id, $terms, $tt_ids, $taxonomy, $append ) {
	if ( ! $append && 'product_cat' === $taxonomy && empty( $tt_ids ) && 'product' === get_post_type( $object_id ) ) {
		$default_term = absint( get_option( 'default_product_cat', 0 ) );
		$tt_ids       = array_map( 'absint', $tt_ids );

		if ( $default_term && ! in_array( $default_term, $tt_ids, true ) ) {
			wp_set_post_terms( $object_id, array( $default_term ), 'product_cat', true );
		}
	}
}