'How do I remove the "{Product} has been removed from your cart because it can no longer be purchased." message in WooCommerce?

I don't want to have customers get the "...has been removed from your cart because it can no longer be purchased..." WooCommerce message when a product that was in their cart get's removed from the online shop.



Solution 1:[1]

Try adding the following code in your theme's functions.php

// Remove the "order again" button
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );

// woocommerce remove message (en&es): [Item] has been removed from your cart because it can no longer be purchased. Please contact us for assistance.

function customize_wc_errors( $error ) {
    if ( strpos( $error, 'has been removed from your cart because' ) !== false ) {
        return '';
    } else if ( strpos( $error, 'ha sido eliminado de tu carrito ya que no' ) !== false ) {
        return '';
    } else {
        return $error; 
    }
}
add_filter( 'woocommerce_add_error', 'customize_wc_errors' );

Solution 2:[2]

Alternatively, you can hook into the specific error message filter, catching all possible translations, and empty the message to prevent it from showing.

Like so:

function customise_cart_item_removed_message( $message, $product ) {
    return '';
}
add_filter( 'woocommerce_cart_item_removed_message', 'customise_cart_item_removed_message', PHP_INT_MAX, 2 );

The woocommerce_cart_item_removed_message filter hook is unique for this error and is defined in wp-content/plugins/woocommerce/includes/class-wc-cart-session.php at line 142 (WooCommerce version 6.2.1).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Philip