Skip to content

Instantly share code, notes, and snippets.

@bogdanpopa90
Created May 11, 2017 12:31
Show Gist options
  • Save bogdanpopa90/4865648336b5b180e134cda825e6a247 to your computer and use it in GitHub Desktop.
Save bogdanpopa90/4865648336b5b180e134cda825e6a247 to your computer and use it in GitHub Desktop.
Custom WooCommerce Cart notice
function capri_woocommerce_add_to_cart_message( $input ) {
$cart_redirect = get_option( 'woocommerce_cart_redirect_after_add' );
// Check for Cart page url
if ( function_exists( 'wc_get_page_id' ) ) {
$cart_url = get_permalink( wc_get_page_id( 'cart' ) );
} else {
$cart_url = get_permalink( woocommerce_get_page_id( 'cart' ) );
}
// Check for Shop page url
if ( function_exists( 'wc_get_page_id' ) ) {
$shop_url = get_permalink( wc_get_page_id( 'shop' ) );
} else {
$shop_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
}
// Get product name from $input
$input = explode( '“',$input );
$title = explode( '”',$input[1] );
$title = $title[0];
if ( function_exists( 'wc_get_page_id' ) ) {
if ( $cart_redirect === 'yes' ) {
$message = sprintf( '<span><i class="fa fa-check" aria-hidden="true"></i><strong>%s</strong> %s</span><span><a href="%s" class="button">%s</a></span>', esc_html( $title ), esc_html__( 'has been added to your cart.', 'THEME' ), $shop_url, esc_html__( 'Continue Shopping', 'THEME' ) );
} else {
$message = sprintf( '<span><i class="fa fa-check" aria-hidden="true"></i><strong>%s</strong> %s</span><span><a href="%s" class="continue-shopping-link">%s</a><a href="%s" class="button">%s</a></span>', esc_html( $title ), esc_html__( 'has been added to your cart.', 'THEME' ), $shop_url, esc_html__( 'Continue Shopping', 'THEME' ), $cart_url, esc_html__( 'View Cart', 'THEME' ) );
}
} else {
if ( $cart_redirect === 'yes' ) {
$message = sprintf( '<span><i class="fa fa-check" aria-hidden="true"></i><strong>%s</strong> %s</span><span><a href="%s" class="button">%s</a></span>', esc_html( $title ), esc_html__( 'has been added to your cart.', 'THEME' ), $shop_url, esc_html__( 'Continue Shopping', 'THEME' ) );
} else {
$message = sprintf( '<span><i class="fa fa-check" aria-hidden="true"></i><strong>%s</strong> %s</span><span><a href="%s" class="continue-shopping-link">%s</a><a href="%s" class="button">%s</a></span>', esc_html( $title ), esc_html__( 'has been added to your cart.', 'THEME' ), $shop_url, esc_html__( 'Continue Shopping', 'THEME' ), $cart_url, esc_html__( 'View Cart', 'THEME' ) );
}
}
return $message;
}
if ( function_exists( 'wc_get_page_id' ) ) {
add_filter( 'wc_add_to_cart_message_html', 'THEME_woocommerce_add_to_cart_message' );
} else {
add_filter( 'wc_add_to_cart_message', 'THEME_woocommerce_add_to_cart_message' );
}
.woocommerce-message {
border-top: none;
border-top-color: transparent;
}
.woocommerce-message {
display: table;
width: 100%;
padding: 1em 2em;
}
.woocommerce-message span {
display: block;
width: 100%;
text-align: center;
}
.woocommerce-message span strong {
text-transform: uppercase;
}
.woocommerce-message .button,
.woocommerce-page .woocommerce-message .button,
.woocommerce .woocommerce-message .button {
float: none;
margin-top: 1em;
}
.woocommerce-message:before {
content: none;
}
.woocommerce-message .fa {
margin-right: 20px;
color: #8ec647;
font-size: 24px;
vertical-align: -2px;
}
.woocommerce-message .continue-shopping-link {
display: inline-block;
margin: 1em 1em 0;
color: #c3c2c4;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
}
.woocommerce-message .continue-shopping-link:hover {
color: #515151;
}
@media screen and (min-width: 480px) {
.woocommerce-message span {
display: table-cell;
width: auto;
text-align: left;
vertical-align: middle;
}
.woocommerce-message span:nth-child(2) {
text-align: right;
}
.woocommerce-message .continue-shopping-link {
margin: 0 0 1em 1em;
}
.woocommerce-message .button,
.woocommerce-page .woocommerce-message .button,
.woocommerce .woocommerce-message .button {
margin-top: 0;
margin-left: 1em;
}
}
@media screen and (min-width: 992px) {
.woocommerce-message .continue-shopping-link {
margin-top: 0;
margin-right: 30px;
}
}
@cuty66
Copy link

cuty66 commented Aug 29, 2018

how can add fixed position successful message box when product added to cart in single product page woocommerce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment