Allow Repeated Additions of Same Product in WooCommerce Cart
By default, WooCommerce updates the product quantity when a user adds the same product to the cart again. However, in some cases, you might want each addition to be treated as a separate item. This guide explains how to modify this behavior using a bit of code.
Why Customize WooCommerce Cart Behavior?
There are specific cases where adding the same product as unique items makes sense — such as custom orders, personalized products, or limited-edition items. Instead of increasing quantity, we want each addition to be handled individually.
How to Add the Same Product Multiple Times
We’ll use WooCommerce’s woocommerce_add_cart_item_data
hook to attach a unique identifier to each cart item. This prevents WooCommerce from merging them based on product ID.
1. Append a Unique Key to Each Cart Item
Place the following code in your theme’s functions.php
or within a custom plugin:
function add_unique_cart_key($cart_item_data, $product_id, $variation_id, $quantity) { $cart_item_data['unique_key'] = md5(microtime() . rand()); return $cart_item_data; } add_filter('woocommerce_add_cart_item_data', 'add_unique_cart_key', 10, 4);
This code ensures that each cart item gets a unique hash, which tells WooCommerce to treat it as a separate entry.
2. Reflect Unique Items in Cart Display
WooCommerce typically groups identical items into one line. Let’s override this behavior by modifying the cart display like this:
function show_unique_cart_item_name($product_name, $cart_item, $cart_item_key) { if (!empty($cart_item['unique_key'])) { $product_name .= ' (Item ID: ' . substr($cart_item['unique_key'], 0, 6) . ')'; } return $product_name; } add_filter('woocommerce_cart_item_name', 'show_unique_cart_item_name', 10, 3);
This will display each instance separately by appending a portion of the unique key to the product title.
Result: Separate Product Entries in Cart
Now, when a customer adds the same product multiple times, it shows up as distinct lines in the cart, each with its own identifier. This is especially useful when the products are customized or need to be tracked individually.
Before You Go Live
Always test such changes on a staging site first. Depending on how your theme and plugins are set up, some conflicts may arise. This solution works best on stores with personalized products or niche functionality.
Helpful Links
To dive deeper into WooCommerce customization, refer to the official WooCommerce docs.