Warning: This method has been deprecated.
WC_Abstract_Legacy_Product::get_total_stock()
Get total stock – This is the stock of parent and children combined.
Description Description
Return Return
(int)
Source Source
File: includes/legacy/abstract-wc-legacy-product.php
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 );
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |