Skip to content

Instantly share code, notes, and snippets.

@VernonGrant
Last active March 10, 2021 03:34
Show Gist options
  • Save VernonGrant/f94c5cbd8f6b3489ebb40f173632e86f to your computer and use it in GitHub Desktop.
Save VernonGrant/f94c5cbd8f6b3489ebb40f173632e86f to your computer and use it in GitHub Desktop.
Styling WooCommerce notices
<?php
/**
* Displays some notices on the cart and checkout pages for easier styling.
*/
function style_woocommerce_notices() {
wc_print_notice( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.', 'success' );
wc_print_notice( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.', 'error' );
wc_print_notice( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.', 'notice' );
wc_print_notice( sprintf( __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="%s">Example Link</a>.', 'woocommerce' ), wc_logout_url() ), 'success' );
wc_print_notice( sprintf( __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="%s">Example Link</a>.', 'woocommerce' ), wc_logout_url() ), 'error' );
wc_print_notice( sprintf( __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="%s">Example Link</a>.', 'woocommerce' ), wc_logout_url() ), 'notice' );
wc_print_notice( sprintf( __( '<a href="%s" tabindex="1" class="button wc-forward">View Cart</a> “Product” has been added to your cart.', 'woocommerce' ), wc_logout_url() ), 'success' );
wc_print_notice( sprintf( __( '<a href="%s" tabindex="1" class="button wc-forward">View Cart</a> “Product” has been added to your cart.', 'woocommerce' ), wc_logout_url() ), 'error' );
wc_print_notice( sprintf( __( '<a href="%s" tabindex="1" class="button wc-forward">View Cart</a> “Product” has been added to your cart.', 'woocommerce' ), wc_logout_url() ), 'notice' );
}
add_action( 'woocommerce_before_cart', 'style_woocommerce_notices', 10 );
add_action( 'woocommerce_before_checkout_form', 'style_woocommerce_notices', 10 );
// ==========================================
// Notices
// ==========================================
.woocommerce .woocommerce-error,
.woocommerce .woocommerce-info,
.woocommerce .woocommerce-message {
color: white;
border-top: none;
a {
color: white;
font-weight: 600;
}
&:before {
color: white;
}
}
.woocommerce .woocommerce-message {
background-color: #4caf50;
a.button {
color: #4caf50;
}
a.button:hover {
background-color: darken(#4caf50, 10%);
color: white;
}
}
.woocommerce .woocommerce-info {
background-color: #2196EF;
a.button {
color: #2196EF;
}
a.button:hover {
background-color: darken(#2196EF, 10%);
color: white;
}
}
.woocommerce .woocommerce-error {
background-color: #f44336;
a.button {
color: #f44336;
}
a.button:hover {
background-color: darken(#f44336, 10%);
color: white;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment