Remove Price Quantity and Subtotal from Cart for Products in a Specific Category

This PHP code removes the price, quantity, and subtotal for products in a specific category from the cart page in WooCommerce.

To do this with PHP code :

  • We hook into the woocommerce_cart_item_name filter.
  • We check if the product associated with the cart item has the ‘free-entry’ term. You may need to change ‘product_cat’ to the appropriate taxonomy for your products.
  • If the product has the term, we replace the item name with just the product name.

The code removes the price, quantity, and subtotal for products using the ‘free-entry’ term in the cart.

You can modify the name of the taxonomy and term to match your own requirements.

For product categories use :

has_term( 'free-item', 'product_cat' )

For product tags use :

has_term( 'free-item', 'product_cat' )

Installation

Copy and paste 1 code snippet to the end of your child themes functions file or custom code snippets plugin.

You’ll also find a 2nd snippet in the download folder which doesn’t remove the link to the single product page unlike the 1st snippet.

Only use 1 snippet.

Note : Do NOT use this PHP code with any other PHP code you’re currently using which removes the price, quantity and/or subtotal line item from the totals table on the cart page as it may conflict causing errors and is NOT needed as this code is tested and works perfectly.

Download Folder

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.