WC_Post_Data::recount_terms_for_product_visibility_change
Deprecated since 11.2.0 Product term-count consistency is now handled by the TermCount service.. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.
Recounts product terms when product visibility changes affect catalog display.
Method of the class: WC_Post_Data{}
No Hooks.
Returns
void. Nothing (null).
Usage
$result = WC_Post_Data::recount_terms_for_product_visibility_change( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids );
- $object_id(int) (required)
- The object ID.
- $terms(array) (required)
- An array of object terms.
- $tt_ids(array) (required)
- An array of term taxonomy IDs.
- $taxonomy(string) (required)
- Taxonomy slug.
- $append(true|false) (required)
- Whether to append new terms to the old terms.
- $old_tt_ids(array) (required)
- The old array of term taxonomy IDs.
Changelog
| Since 10.4.0 | Introduced. |
| Deprecated since 11.2.0 | Product term-count consistency is now handled by the TermCount service. |
WC_Post_Data::recount_terms_for_product_visibility_change() WC Post Data::recount terms for product visibility change code WC 11.2.1
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 );
}
}