WC_Abstract_Legacy_Product::get_total_stock │ public │ WC 1.0

Deprecated since 3.0.0. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

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

Method of the class: WC_Abstract_Legacy_Product{}

No Hooks.

Returns

int.

Usage

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

Changelog

Deprecated since 3.0.0

WC_Abstract_Legacy_Product::get_total_stock() code WC 11.2.1

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