Merge pull request #3564 from ragulka/stock-action-hooks

Add stock set, increase and reduce action hooks
This commit is contained in:
Mike Jolley 2013-08-02 03:11:05 -07:00
commit e9a168c2ee
1 changed files with 6 additions and 0 deletions

View File

@ -162,6 +162,8 @@ class WC_Product {
$this->stock = intval( $amount );
update_post_meta( $this->id, '_stock', $this->stock );
do_action( 'woocommerce_product_set_stock', $this );
// Out of stock attribute
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
$this->set_stock_status( 'outofstock' );
@ -188,6 +190,8 @@ class WC_Product {
$this->stock = $this->stock - $by;
update_post_meta( $this->id, '_stock', $this->stock );
do_action( 'woocommerce_product_reduce_stock', $this, $by );
// Out of stock attribute
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
$this->set_stock_status( 'outofstock' );
@ -212,6 +216,8 @@ class WC_Product {
$this->stock = $this->stock + $by;
update_post_meta( $this->id, '_stock', $this->stock );
do_action( 'woocommerce_product_increase_stock', $this, $by );
// Out of stock attribute
if ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
$this->set_stock_status( 'instock' );