wc_empty_cart_message()WC 3.1.0

Show notice if cart is empty.

Hooks from the function

Return

null. Nothing (null).

Usage

wc_empty_cart_message();

Changelog

Since 3.1.0 Introduced.

wc_empty_cart_message() code WC 8.6.1

function wc_empty_cart_message() {
	$notice = wc_print_notice(
		wp_kses_post(
			/**
			 * Filter empty cart message text.
			 *
			 * @since 3.1.0
			 * @param string $message Default empty cart message.
			 * @return string
			 */
			apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) )
		),
		'notice',
		array(),
		true
	);

	// This adds the cart-empty classname to the notice to preserve backwards compatibility (for styling purposes etc).
	$notice = str_replace( 'class="woocommerce-info"', 'class="cart-empty woocommerce-info"', $notice );

	// Return the notice within a consistent wrapper element. This is targetted by some scripts such as cart.js.
	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	echo '<div class="wc-empty-cart-message">' . $notice . '</div>';
}