Automattic\WooCommerce\Internal

TermCount::handle_set_object_terms │ public │ WC 11.2.0

Recounts product terms after count-affecting visibility relationships are added.

Removals are recounted by handle_deleted_term_relationships(), which runs before the set_object_terms hook during wp_set_object_terms().

Метод класса: TermCount{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$TermCount = new TermCount();
$TermCount->handle_set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ): void;
$object_id(int) (обязательный)
Object ID.
$terms(array<int|string>) (обязательный)
An array of object term IDs or slugs.
$tt_ids(array<int|string>) (обязательный)
An array of term taxonomy IDs.
$taxonomy(строка) (обязательный)
Taxonomy slug.
$append(true|false) (обязательный)
Whether to append new terms to the old terms.
$old_tt_ids(array<int|string>) (обязательный)
The old array of term taxonomy IDs.

Список изменений

С версии 11.2.0 Введена.

Код TermCount::handle_set_object_terms() WC 11.2.2

public function handle_set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ): void {
	$object_id = absint( $object_id );

	if ( 'product_visibility' !== $taxonomy || 0 === $object_id || ! is_array( $tt_ids ) || ! is_array( $old_tt_ids ) ) {
		return;
	}

	$new_tt_ids      = $this->normalize_ids( $tt_ids );
	$old_tt_ids      = $this->normalize_ids( $old_tt_ids );
	$counting_tt_ids = $this->get_count_affecting_visibility_term_taxonomy_ids();

	$removed_tt_ids = $append ? array() : array_diff( $old_tt_ids, $new_tt_ids );

	// When the removed term taxonomy IDs include any count-affecting visibility terms, the recount will be handled by handle_deleted_term_relationships().
	if ( ! empty( array_intersect( $removed_tt_ids, $counting_tt_ids ) ) ) {
		return;
	}

	$added_tt_ids = $append ? $new_tt_ids : array_diff( $new_tt_ids, $old_tt_ids );

	if ( ! empty( array_intersect( $added_tt_ids, $counting_tt_ids ) ) ) {
		_wc_recount_terms_by_product( $object_id );
	}
}