WC_Brands::recount_after_stock_change()publicWC 1.0

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 9.4.2

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 );
	}
}