Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active February 4, 2019 23:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bekarice/491e871ca70dddc93f53 to your computer and use it in GitHub Desktop.
Save bekarice/491e871ca70dddc93f53 to your computer and use it in GitHub Desktop.
WooCommerce: Show a notice throughout the store if the cart is empty
/**
* Tutorial: http://www.skyverge.com/blog/check-if-woocommerce-cart-is-empty/
**/
function skyverge_empty_cart_notice() {
if ( WC()->cart->get_cart_contents_count() == 0 ) {
wc_print_notice( __( 'Get free shipping if your order is over $60!', 'woocommerce' ), 'notice' );
// Change notice text as desired
}
}
// Add to cart page
add_action( 'woocommerce_check_cart_items', 'skyverge_empty_cart_notice' );
// Add to shop archives & product pages
add_action( 'woocommerce_before_main_content', 'skyverge_empty_cart_notice' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment