WooCommerce : Change “Add to Cart” Text if Product Already in Cart.

Code

If one a product is already in cart, displaying a different text instead of “Add to Cart” text for “add_to_cart” button is a nice idea.
When a product is in cart , woocomerce still show ‘Add to Cart’ text. There is no information on shop page or product page that ‘s this product is already in cart.It is simple in WooCommerce because WooCommerce have filter and hook to change this add to cart button text.But Before changing “Add to Cart” button text, we first need to check if the item is already in cart.

There are two places where user can add product to cart
1. Shop page(Loop Page)
2. Single product page

1. Shop page(Loop Page)

The Filter added by WooCommerce For WooCommerce product loop is ‘woocommerce_product_add_to_cart_text’ Filter.

// Shop page
function ChangeAddToCartButtonTextLoop( $label, $product ) {   
  if ( $product->get_type() == 'simple' && $product->is_purchasable() && $product->is_in_stock() ) {     
    foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
      $_product = $values['data'];
      if( get_the_ID() == $_product->get_id() ) {
        $label = __('Already in Cart. Add again?', 'woocommerce');
      }
    }      
  }   
return $label;  
}
add_filter('woocommerce_product_add_to_cart_text','ChangeAddToCartButtonTextLoop',99,2 );

Example:

WooCommerce : Change “Add to Cart” Text if Product Already in Cart. – screenshot 1

2. Single Product Page

The Filter added by WooCommerce For WooCommerce Single Product Pag is ‘woocommerce_product_single_add_to_cart_text’ Filter.

// Single Product page
function ChangeAddToCartButtonTextSingleProduct( $label ) {
  foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
    $product = $values['data'];
    if( get_the_ID() == $product->get_id() ) {
      $label = __('Already in Cart. Add again?', 'woocommerce');
    }
  }   
return $label;
}
add_filter('woocommerce_product_single_add_to_cart_text','ChangeAddToCartButtonTextSingleProduct');

Example:

WooCommerce : Change “Add to Cart” Text if Product Already in Cart. – screenshot 2

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, the Jaipur-based IT company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

Taxi app development cost in Saudi Arabia 2026 banner: Eoxys blue panel with a phone showing turn-by-turn navigation on a car dashboard

Taxi App Development Cost in Saudi Arabia (2026)

A ride in Saudi Arabia only counts as a completed trip when four things hold at once: a licensed, verified…

Shafeeq Khan
November 21, 2026
Colour photograph illustrating the Eoxys blog post 'Perplexity SEO: How to Get Your Business Cited by Perplexity', used as the featured image for perplexity seo.

Perplexity SEO: How to Get Your Business Cited by Perplexity

Perplexity is the answer engine many researchers, analysts and B2B buyers use when they want sources, not just an answer….

Shafeeq Khan
November 21, 2026
RAG chatbot architecture and guardrails banner with archive shelving representing a company knowledge base

RAG Chatbot Architecture and Guardrails: A Production Guide

A chatbot can quote a policy accurately and still give an unacceptable answer: the policy might be withdrawn, or belong…

Shafeeq Khan
November 20, 2026
,

Leave a Reply

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