Enable Duplicate Product Entries in WooCommerce Cart
WooCommerce typically updates the product quantity in the cart when the same item is added again. But what if you want to show them as separate items instead? With a bit of code, you can make WooCommerce accept multiple entries of the same product as unique.
Why You Might Need This
This feature is particularly helpful if your store offers personalized products or handles single-use items. Each time the product is added, it’s treated independently instead of increasing the quantity.
Implementing the Custom Behavior
Let’s modify how WooCommerce recognizes cart items by using a unique ID, which will trick the cart into displaying them separately.
Step 1: Add a Unique Cart Key
Insert the below snippet into your theme’s functions.php
file:
function wc_add_unique_cart_item_data($cart_item_data, $product_id, $variation_id, $quantity) { $cart_item_data['custom_unique'] = md5(uniqid(mt_rand(), true)); return $cart_item_data; } add_filter('woocommerce_add_cart_item_data', 'wc_add_unique_cart_item_data', 10, 4);
This ensures each cart item has a different signature, preventing merging of the same product.
Step 2: Make Cart Display Each Item Uniquely
WooCommerce usually groups identical items together. To stop that, apply this code:
function wc_display_custom_cart_item_name($name, $item, $key) { if (isset($item['custom_unique'])) { $name .= ' (' . substr($item['custom_unique'], 0, 5) . ')'; } return $name; } add_filter('woocommerce_cart_item_name', 'wc_display_custom_cart_item_name', 10, 3);
It will append a short unique string to the product name, showing them as separate items in the cart.
End Result
Now, each product added — even if it’s the same one — appears separately in the cart. This is useful when selling customizable or single-purchase items.
Points to Remember
Always test these tweaks thoroughly before rolling them out on your live site. Some third-party plugins or cart features might behave unexpectedly with this setup.
Need More Customizations?
Explore the WooCommerce documentation for more powerful hooks and cart customization methods.