WC_REST_Products_V2_Controller::batch_itemspublicWC 10.4.0

Bulk create, update, and delete items.

This method extends the parent batch_items functionality by deferring term counting to optimize performance when processing multiple products that may share common terms.

Method of the class: WC_REST_Products_V2_Controller{}

No Hooks.

Returns

Array. Array of WP_Error or WP_REST_Response objects for each processed item.

Usage

$WC_REST_Products_V2_Controller = new WC_REST_Products_V2_Controller();
$WC_REST_Products_V2_Controller->batch_items( $request );
$request(WP_REST_Request) (required)
Full details about the request containing arrays of products to create, update, or delete.

Changelog

Since 10.4.0 Introduced.
Since 10.4.0 Added term counting optimization for bulk operations.

WC_REST_Products_V2_Controller::batch_items() code WC 10.4.3

public function batch_items( $request ) {
	$already_deferred = wp_defer_term_counting();
	wp_defer_term_counting( true );
	try {
		return parent::batch_items( $request );
	} finally {
		// Be sure to trigger term counting already processed terms even if there was an exception unless something had already deferred it.
		wp_defer_term_counting( $already_deferred );
	}
}