Change “You cannot add another product to your cart” message in WooCommerce

If you are selling products that can only be sold individually, then you might be wondering how to replace the error message that shows in your WooCommerce shop.

You can do so by adding this snippet below in your functions.php file.

<?php /** * WPHarvest.com * WordPress and WooCommerce Resources * Change "You cannot add another product to your cart" message in WooCommerce */ add_filter('woocommerce_cart_product_cannot_add_another_message', 'wpharvest_sold_individually_text'); function wpharvest_sold_individually_text($message, $product_data){ $message = sprintf( __( 'Sorry, you can only purchase one &quot;%s&quot; at a time.', 'woocommerce' ), $product_data->get_name() ); return $message; }
Code language: HTML, XML (xml)

Hope this snippet helped you. If it stops working for you or are having any issue, please leave a comment below.