In Woocommerce, I would like to update the ‘add to cart’ text when the corresponding product is removed from the cart.
I have the following code which changes the text when the product is added to the cart:
add_filter( 'woocommerce_product_single_add_to_cart_text', 'already_in_cart_single_product' );
function already_in_cart_single_product( $label ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$product = $values['data'];
if( get_the_ID() == $product->get_id() ) {
$label = __('Product already in Cart. Add again?', 'woocommerce');
}
}
return $label;
}
And would like something that then reverts the text back again after the product is removed from the cart.
New contributor
Rv5 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.