Hide stock amount when children are involved

Closes #10172
This commit is contained in:
Mike Jolley 2016-01-27 13:00:50 +00:00
parent 30ee8aaef0
commit f8df682f34
2 changed files with 8 additions and 7 deletions

View File

@ -222,15 +222,17 @@ class WC_Product {
*/
public function get_total_stock() {
if ( empty( $this->total_stock ) ) {
$this->total_stock = max( 0, $this->get_stock_quantity() );
if ( sizeof( $this->get_children() ) > 0 ) {
$this->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 );
$this->total_stock += max( 0, wc_stock_amount( $stock ) );
}
}
} else {
$this->total_stock = $this->get_stock_quantity();
}
}
return wc_stock_amount( $this->total_stock );

View File

@ -222,7 +222,7 @@ class WC_Admin_Post_Types {
$columns['sku'] = __( 'SKU', 'woocommerce' );
}
if ( 'yes' == get_option( 'woocommerce_manage_stock' ) ) {
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
$columns['is_in_stock'] = __( 'Stock', 'woocommerce' );
}
@ -395,19 +395,18 @@ class WC_Admin_Post_Types {
echo '</a>';
break;
case 'is_in_stock' :
if ( $the_product->is_in_stock() ) {
echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
} else {
echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
}
if ( $the_product->managing_stock() ) {
echo ' &times; ' . $the_product->get_total_stock();
// If the product has children, a single stock level would be misleading as some could be -ve and some +ve, some managed/some unmanaged etc so hide stock level in this case.
if ( $the_product->managing_stock() && ! sizeof( $the_product->get_children() ) ) {
echo ' (' . $the_product->get_total_stock() . ')';
}
break;
default :
break;
}