WC_Product_Data_Store_CPT::read_stock_quantity( WC_Product $product, int|float $new_stock = null )

Re-reads stock from the DB ignoring changes.


Description Description


Parameters Parameters

$product

(Required) Product object.

$new_stock

(Optional) New stock level if already read.

Default value: null


Top ↑

Source Source

File: includes/data-stores/class-wc-product-data-store-cpt.php

	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 );
	}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.