WC_Meta_Box_Product_Data::persist_external_product_stock_data │ private static │ WC 1.0

Persist the stock data enforced by the external product class.

External product setters normalize stock values while the existing product data is read. The submitted values therefore match the in-memory values and are not detected as changes, leaving stale stock meta, lookup, and visibility data behind unless they are synchronized explicitly.

Method of the class: WC_Meta_Box_Product_Data{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Meta_Box_Product_Data::persist_external_product_stock_data( $product ): void;
$product(WC_Product) (required)
External product object.

WC_Meta_Box_Product_Data::persist_external_product_stock_data() code WC 11.1.2

private static function persist_external_product_stock_data( WC_Product $product ): void {
	update_post_meta( $product->get_id(), '_manage_stock', 'no' );
	update_post_meta( $product->get_id(), '_stock_status', ProductStockStatus::IN_STOCK );
	update_post_meta( $product->get_id(), '_backorders', 'no' );
	wp_remove_object_terms( $product->get_id(), ProductStockStatus::OUT_OF_STOCK, 'product_visibility' );

	/**
	 * Product data store.
	 *
	 * @var WC_Data_Store $data_store
	 */
	$data_store = $product->get_data_store();
	if ( $data_store->has_callable( 'refresh_product_lookup_table' ) ) {
		// @phpstan-ignore-next-line method.notFound (Guarded by has_callable() and called via __call() on the underlying product data store instance.)
		$data_store->refresh_product_lookup_table( $product->get_id() );
	}
}