Skip to content

Instantly share code, notes, and snippets.

@davidtowoju
Last active January 12, 2018 14:00
Show Gist options
  • Save davidtowoju/ac1ebc055eff20a0b50746cd2ffa8ba2 to your computer and use it in GitHub Desktop.
Save davidtowoju/ac1ebc055eff20a0b50746cd2ffa8ba2 to your computer and use it in GitHub Desktop.
Change WooCommerce 3.0+ “has been added to cart” message
function mytheme_custom_add_to_cart_message($message, $product_id = null) {
$titles[] = get_the_title( key($product_id));
$titles = array_filter( $titles );
$added_text = sprintf( _n( '%s has been added to cart.', '%s have been added to cart', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) ); //Change the message here
$message = sprintf( '%s <a href="%s" class="button">%s</a>',
esc_html( $added_text ),
esc_url( wc_get_page_permalink( 'checkout' ) ), // Change to esc_url( wc_get_page_permalink( 'cart' ) ), if you want users to go to cart
esc_html__( 'Pay Now', 'woocommerce' ));
return $message;
}
add_filter( 'wc_add_to_cart_message_html', 'mytheme_custom_add_to_cart_message', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment