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.
Method of the class: ProductButton{}
No Hooks.
Return
number
. The number of items in the cart.
Usage
// private - for code of main (parent) class only $result = $this->get_cart_item_quantities_by_product_id( $product_id );
- $product_id(number) (required)
- The product id.
ProductButton::get_cart_item_quantities_by_product_id() ProductButton::get cart item quantities by product id code WC 9.6.0
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; }