MainWP Community

Subscription Product in Cart Notice in WooCommerce

Display cart notice if a subscription product is in the cart if using WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

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' );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.