StEst
StEst

Reputation: 13

Edit '%s has been added to your cart' text without removing 'view cart' button

I've been trying to edit the '%s has been added to your cart' text, not really experienced in coding.. so I tried a few different codes I found online, but they all seem to remove the 'view cart' button, which I want it to stay.

Is there a way to edit the message without removing the button?

This is the code I'm using:

/**
* @snippet       Edit "has been added to your cart" message
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @compatible    WC 5
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/
 
add_filter( 'wc_add_to_cart_message_html', 'bbloomer_custom_add_to_cart_message' );
 
function bbloomer_custom_add_to_cart_message() {
   $message = 'Nicely done!' ;
   return $message;
}

Thanks in advance! Steve

Upvotes: 1

Views: 553

Answers (1)

Christopher Geary
Christopher Geary

Reputation: 715

You need to include the HTML of the button in the string you return from the filter. For example:

add_filter( 'wc_add_to_cart_message_html', function ( $message ) {

    $text = 'Product added to your cart.';

    return sprintf(
        '<a href="%s" tabindex="1" class="button wc-forward">%s</a> %s',
        esc_url( wc_get_cart_url() ),
        esc_html__( 'View cart', 'woocommerce' ),
        esc_html( $text )
    );

} );

Replace "Product added to your cart." with your desired text.

Upvotes: 1

Related Questions