mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-05 12:32:23 +08:00
16 lines
681 B
Text
16 lines
681 B
Text
function woo_sub_in_cart_notice() {
|
|
if ( WC()->cart->get_cart_contents_count() == 0 ) {
|
|
wc_print_notice( __( 'Your cart contains nothing!', 'woocommerce' ), 'notice' );
|
|
} else {
|
|
if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
|
|
wc_print_notice( __( 'Your cart contains a subscription!', 'woocommerce' ), 'notice' );
|
|
} else {
|
|
wc_print_notice( __( 'Your cart is NOT empty, but does NOT contain a subscription!', 'woocommerce' ), 'notice' );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add to cart page
|
|
add_action( 'woocommerce_check_cart_items', 'woo_sub_in_cart_notice' );
|
|
// Add to shop archives & product pages
|
|
add_action( 'woocommerce_before_main_content', 'woo_sub_in_cart_notice' );
|