WC_Post_Data::recount_terms_for_product_visibility_change │ public static │ WC 10.4.0

Устарела с версии 11.2.0 Product term-count consistency is now handled by the TermCount service.. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Recounts product terms when product visibility changes affect catalog display.

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

Хуков нет.

Возвращает

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

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

$result = WC_Post_Data::recount_terms_for_product_visibility_change( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids );
$object_id(int) (обязательный)
The object ID.
$terms(массив) (обязательный)
An array of object terms.
$tt_ids(массив) (обязательный)
An array of term taxonomy IDs.
$taxonomy(строка) (обязательный)
Taxonomy slug.
$append(true|false) (обязательный)
Whether to append new terms to the old terms.
$old_tt_ids(массив) (обязательный)
The old array of term taxonomy IDs.

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

С версии 10.4.0 Введена.
Устарела с 11.2.0 Product term-count consistency is now handled by the TermCount service.

Код WC_Post_Data::recount_terms_for_product_visibility_change() WC 11.2.2

public static function recount_terms_for_product_visibility_change( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
	wc_deprecated_function( __FUNCTION__, '11.2.0' );

	if ( 'product_visibility' !== $taxonomy ) {
		return;
	}

	if ( $append ) {
		$modified_tt_ids = $tt_ids;
	} else {
		$modified_tt_ids = array_merge( array_diff( $tt_ids, $old_tt_ids ), array_diff( $old_tt_ids, $tt_ids ) );
	}

	if ( empty( $modified_tt_ids ) ) {
		return;
	}

	// Despite the name, wc_get_product_visibility_term_ids() actually returns an associative array with term_taxonomy_ids.
	$visibility_tt_ids = wc_get_product_visibility_term_ids();

	$tt_ids_modifying_term_counts = array();
	if ( ! empty( $visibility_tt_ids['exclude-from-catalog'] ) ) {
		$tt_ids_modifying_term_counts[] = $visibility_tt_ids['exclude-from-catalog'];
	}

	if ( ! empty( $visibility_tt_ids['outofstock'] ) && 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
		$tt_ids_modifying_term_counts[] = $visibility_tt_ids['outofstock'];
	}

	if ( ! empty( array_intersect( $modified_tt_ids, $tt_ids_modifying_term_counts ) ) ) {
		_wc_recount_terms_by_product( $object_id );
	}
}