WC_Abstract_Legacy_Product::get_total_stock()publicWC 1.0

Устарела с версии 3.0.0. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Get total stock - This is the stock of parent and children combined.

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

Хуков нет.

Возвращает

int.

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

$WC_Abstract_Legacy_Product = new WC_Abstract_Legacy_Product();
$WC_Abstract_Legacy_Product->get_total_stock();

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

Устарела с 3.0.0

Код WC_Abstract_Legacy_Product::get_total_stock() WC 8.7.0

public function get_total_stock() {
	wc_deprecated_function( 'WC_Product::get_total_stock', '3.0', 'get_stock_quantity on each child. Beware of performance issues in doing so.' );
	if ( sizeof( $this->get_children() ) > 0 ) {
		$total_stock = max( 0, $this->get_stock_quantity() );

		foreach ( $this->get_children() as $child_id ) {
			if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) {
				$stock = get_post_meta( $child_id, '_stock', true );
				$total_stock += max( 0, wc_stock_amount( $stock ) );
			}
		}
	} else {
		$total_stock = $this->get_stock_quantity();
	}
	return wc_stock_amount( $total_stock );
}