Disable Quantity Field on WooCommerce Cart Page

Learn how to disable the quantity field from the WooCommerce cart page. It will be replaced with a dynamic quantity count that reflects the actual quantity of each product in the cart. This tutorial provides a simple solution to customize the cart layout and improve user experience.

Disable Quantity Field on Cart Page

* Snippet Name:  Disable quantity field on the cart page and add product quantiy count
* Snippet Author:  wpsnippets.dev

// Set dynamic quantity for products in the cart
function wps_set_dynamic_cart_item_quantity($product_quantity, $cart_item_key, $cart_item) {
    // Check if it's the cart page
    if (is_cart()) {
        $product_quantity = $cart_item['quantity'];         // Get the actual quantity of the product in the cart
    return $product_quantity;
add_filter('woocommerce_cart_item_quantity', 'wps_set_dynamic_cart_item_quantity', 10, 3);

Code Explanation

  • This snippet removes the quantity field from the WooCommerce cart page using the woocommerce_cart_item_quantity filter. It adds a dynamic quantity count next to each product name in the cart using the woocommerce_cart_item_name action, fetching the product quantity directly from the cart item.
  • It enhances the cart layout by simplifying the interface and providing clear visibility of the product quantities.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top