To edit the message, you can use since WooCommerce 4.5.0 the woocommerce_cart_product_cannot_add_another_message
filter hook.
/**
* Filters message about more than 1 product being added to cart.
*
* @since 4.5.0
* @param string $message Message.
* @param WC_Product $product_data Product data.
*/
function filter_woocommerce_cart_product_cannot_add_another_message( $message, $product_data ) {
// New text
$message = __( 'My new message', 'woocommerce' );
return $message;
}
add_filter( 'woocommerce_cart_product_cannot_add_another_message', 'filter_woocommerce_cart_product_cannot_add_another_message', 10, 2 );
To hide the message completely, just replace
// New text
$message = __( 'My new message', 'woocommerce' );
With
// New text
$message = '';
However, the "problem" with the above solution is that the message is now hidden, but the woocommerce-error
(red box) and view-cart
button is still displayed.
So while using the filter hook, you can add some extra jQuery to hide the woocommerce-error
Note: although the below works, it is never a good idea to hide error messages. These are there for a reason, to make a customer aware of something. Hence, this solution is a bit 'tricky'.
But to answer your question, you can use:
function filter_woocommerce_cart_product_cannot_add_another_message( $message, $product_data ) {
$message = '<div class="hide-this-error-message"></div>';
return $message;
}
add_filter( 'woocommerce_cart_product_cannot_add_another_message', 'filter_woocommerce_cart_product_cannot_add_another_message', 10, 2 );
function action_wp_footer() {
?>
<script>
jQuery(document).ready(function($) {
$( '.hide-this-error-message' ).closest( 'ul.woocommerce-error' ).hide();
});
</script>
<?php
}
add_action( 'wp_footer', 'action_wp_footer' );