WC_Product_Data_Store_CPT::read_stock_quantity()publicWC 1.0

Re-reads stock from the DB ignoring changes.

Method of the class: WC_Product_Data_Store_CPT{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT();
$WC_Product_Data_Store_CPT->read_stock_quantity( $product, $new_stock );
$product(WC_Product) (required) (passed by reference — &)
Product object.
$new_stock(int|float)
New stock level if already read.
Default: null

WC_Product_Data_Store_CPT::read_stock_quantity() code WC 8.7.0

public function read_stock_quantity( &$product, $new_stock = null ) {
	$object_read = $product->get_object_read();
	$product->set_object_read( false ); // This makes update of qty go directly to data- instead of changes-array of the product object (which is needed as the data should hold status of the object as it was read from the db).
	$product->set_stock_quantity( is_null( $new_stock ) ? get_post_meta( $product->get_id(), '_stock', true ) : $new_stock );
	$product->set_object_read( $object_read );
}