wc_update_product_stock_status

Update a product's stock status.

Description

wc_update_product_stock_status( (int) $product_id, (int) $status ); 

Parameters (2)

0. $product_id (int)
The product id.
1. $status (int)
The status.

Usage

  1. if ( !function_exists( 'wc_update_product_stock_status' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-stock-functions.php'; 
  3.  
  4. // The product id. 
  5. $product_id = -1; 
  6.  
  7. // The status. 
  8. $status = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_update_product_stock_status($product_id, $status); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-stock-functions.php  
  1. function wc_update_product_stock_status( $product_id, $status ) { 
  2. $product = wc_get_product( $product_id ); 
  3. if ( $product ) { 
  4. $product->set_stock_status( $status ); 
  5. $product->save();