Automattic\WooCommerce\Blocks\BlockTypes
ProductButton::get_cart_item_quantities_by_product_id()
Get the number of items in the cart for a given product id.
Метод класса: ProductButton{}
Хуков нет.
Возвращает
number
. The number of items in the cart.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_cart_item_quantities_by_product_id( $product_id );
- $product_id(number) (обязательный)
- The product id.
Код ProductButton::get_cart_item_quantities_by_product_id() ProductButton::get cart item quantities by product id WC 9.5.1
private function get_cart_item_quantities_by_product_id( $product_id ) { if ( ! isset( WC()->cart ) ) { return 0; } $cart = WC()->cart->get_cart_item_quantities(); return isset( $cart[ $product_id ] ) ? $cart[ $product_id ] : 0; }