Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
HandlerRegistry::get_cart_product_ids
Get cart product IDs from various sources. Handles loading cart products from location context or request params.
Метод класса: HandlerRegistry{}
Хуков нет.
Возвращает
array<int>. The product IDs from the cart. Returns recent products for preview in editor context only.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_cart_product_ids( $request );
- $request(WP_REST_Request|null)
- Optional REST request for editor context.
По умолчанию:null
Код HandlerRegistry::get_cart_product_ids() HandlerRegistry::get cart product ids WC 11.3.0
private function get_cart_product_ids( $request = null ) {
if ( $request ) {
// In editor context (REST request), show sample products for preview. Only emails to the customer show live data.
$recent_product_ids = wc_get_products(
array(
'status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'limit' => 3,
'return' => 'ids',
)
);
return ! empty( $recent_product_ids ) ? $recent_product_ids : array();
}
// In frontend/email context, return empty array when no cart is found.
return array();
}