WC_Post_Data::force_default_term( int $object_id, array $terms, array $tt_ids, string $taxonomy, bool $append )

Ensure default category gets set.


Description Description


Parameters Parameters

$object_id

(Required) Product ID.

$terms

(Required) Terms array.

$tt_ids

(Required) Term ids array.

$taxonomy

(Required) Taxonomy name.

$append

(Required) Are we appending or setting terms.


Top ↑

Source Source

File: includes/class-wc-post-data.php

	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 );
			}
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.