Skip to content

Instantly share code, notes, and snippets.

@chrdesigner
Created August 27, 2014 19:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrdesigner/a717003315ba4ce7e0b7 to your computer and use it in GitHub Desktop.
Save chrdesigner/a717003315ba4ce7e0b7 to your computer and use it in GitHub Desktop.
Custom Add To Cart Messages
<?php
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message( $product_id ) {
$product_id = $_REQUEST[ 'product_id' ];
if ( is_array( $product_id ) ) {
$titles = array();
foreach ( $product_id as $id ) {
$titles[] = get_the_title( $id );
}
$added_text = sprintf( __( 'Added &quot;%s&quot; to your cart.', 'woocommerce' ), join( __( '&quot; and &quot;', 'woocommerce' ), array_filter( array_merge( array( join( '&quot;, &quot;', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) );
} else {
$added_text = sprintf( __( '&quot;%s&quot; was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
}
// Output success messages
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
$message = sprintf(
'<a href="%s" class="alert-link">%s &rarr;</a> %s',
$return_to, __( 'Continue Shopping', 'woocommerce' ),
$added_text
);
else :
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('<div class="alignleft col-md-9 no-margin">'. $added_text .'</div><div id="content-btns" class="alignleft col-md-3 no-margin"><a href="'.get_permalink( wc_get_page_id( 'cart' ) ).'" class="buttons right-button">Ver Cesta</a><small class="buttons text-center">ou</small><a href="'.$return_to.'" class="buttons left-button">Continuar Comprando</a></div>');
endif;
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment