WC_Brands::recount_after_stock_change()
Recount the brands after the stock amount changes.
Method of the class: WC_Brands{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WC_Brands = new WC_Brands(); $WC_Brands->recount_after_stock_change( $product_id );
- $product_id(int) (required)
- Product ID.
WC_Brands::recount_after_stock_change() WC Brands::recount after stock change code WC 9.5.1
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 ) { $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 ); } }