yit_update_product_stock

The YITH WooCommerce Wishlist yit update product stock function.

Description

yit_update_product_stock( $product, (int) $stock_quantity = 1, (string) $operation = 'set' ); 

Parameters (3)

0. $product
The product.
1. $stock_quantity — Optional. (int) => 1
The stock quantity.
2. $operation — Optional. (string) => 'set'
The operation.

Usage

  1. if ( !function_exists( 'yit_update_product_stock' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-wishlist/plugin-fw/yit-woocommerce-compatibility.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // The stock quantity. 
  8. $stock_quantity = 1; 
  9.  
  10. // The operation. 
  11. $operation = 'set'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = yit_update_product_stock($product, $stock_quantity, $operation); 
  15.  

Defined (1)

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

/plugin-fw/yit-woocommerce-compatibility.php  
  1. function yit_update_product_stock( $product, $stock_quantity = 1, $operation = 'set' ) { 
  2. if ( function_exists( 'wc_update_product_stock' ) ) { 
  3. $stock = wc_update_product_stock( $product, $stock_quantity, $operation ); 
  4. } else { 
  5. switch ( $operation ) { 
  6. case 'increase': 
  7. $stock = $product->increase_stock( $stock_quantity ); 
  8. break; 
  9. case 'decrease': 
  10. $stock = $product->reduce_stock( $stock_quantity ); 
  11. break; 
  12. case 'set': 
  13. default: 
  14. $stock = $product->set_stock( $stock_quantity ); 
  15. break; 
  16.  
  17. return $stock;