Abstract_WC_Order_Data_Store_CPT::prime_product_post_caches_for_order_items
Primes post caches for products which are referenced in line items with 'line_item' type.
Although the product data store can be replaced, maintaining the posts table connection, as with HPOS, is necessary for products to function properly. We can therefore prime the post cache directly without compromising store isolation.
Method of the class: Abstract_WC_Order_Data_Store_CPT{}
No Hooks.
Returns
void. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->prime_product_post_caches_for_order_items( $line_items_all, $raw_meta_data_collection ): void;
- $line_items_all(array<int,object{order_item_id:int, order_item_type:string}>) (required)
- Line item entries.
- $raw_meta_data_collection(array) (required)
- .
Changelog
| Since 10.8.0 | Introduced. |
Abstract_WC_Order_Data_Store_CPT::prime_product_post_caches_for_order_items() Abstract WC Order Data Store CPT::prime product post caches for order items code WC 11.1.2
private function prime_product_post_caches_for_order_items( array $line_items_all, array $raw_meta_data_collection ): void {
$product_ids = array();
foreach ( $line_items_all as $line_item ) {
if ( 'line_item' === $line_item->order_item_type ) {
foreach ( $raw_meta_data_collection[ $line_item->order_item_id ] ?? array() as $meta ) {
if ( ( '_variation_id' === $meta->meta_key || '_product_id' === $meta->meta_key ) && $meta->meta_value > 0 ) {
$product_ids[] = (int) $meta->meta_value;
}
}
}
}
_prime_post_caches( array_unique( $product_ids ) );
}