Created
August 27, 2014 19:16
-
-
Save chrdesigner/a717003315ba4ce7e0b7 to your computer and use it in GitHub Desktop.
Custom Add To Cart Messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 "%s" to your cart.', 'woocommerce' ), join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( join( '", "', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) ); | |
} else { | |
$added_text = sprintf( __( '"%s" 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 →</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