WC_Brands::recount_after_stock_change
Recount the brands after the stock amount changes.
Метод класса: WC_Brands{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WC_Brands = new WC_Brands(); $WC_Brands->recount_after_stock_change( $product_id );
- $product_id(int) (обязательный)
- Product ID.
Код WC_Brands::recount_after_stock_change() WC Brands::recount after stock change WC 10.4.3
public function recount_after_stock_change( $product_id ) {
if ( 'yes' !== get_option( 'woocommerce_hide_out_of_stock_items' ) || empty( $product_id ) ) {
return;
}
$product_terms = get_the_terms( $product_id, 'product_brand' );
if ( ! $product_terms ) {
return;
}
if ( wp_defer_term_counting() ) {
// When deferring term counts, we're using the built in handling of `wp_update_term_count()` to deal with the deferring
// and, though, this will cause both the standard and stock based counts to be rerun, it is still more efficient
// in cases where deferred term counting was warranted.
$product_terms = get_the_terms( $product_id, 'product_brand' );
if ( is_array( $product_terms ) ) {
wp_update_term_count( array_column( $product_terms, 'term_taxonomy_id' ), 'product_brand' );
}
return;
}
$product_brands = array();
foreach ( $product_terms as $term ) {
$product_brands[ $term->term_id ] = $term->parent;
}
_wc_term_recount( $product_brands, get_taxonomy( 'product_brand' ), false, false );
}