wc_get_cart_url()WC 2.5.0

Returns a link to the Cart page.

If the Cart page does not exist, the function get_home_url() will be executed and the URL of the site's homepage will be returned.

Hooks from the function

Returns

String. A link to the cart page or the site's homepage if the cart page does not exist.

Usage

wc_get_cart_url();

Examples

0

#1 Display a link to the shopping cart

<a class="cart-link" href="<?php echo esc_url( wc_get_cart_url() ); ?>">
	View cart
</a>

Changelog

Since 2.5.0 Introduced.
Since 9.3.0 To support shortcodes on other pages besides the main cart page, this returns the current URL if it is the cart page.

wc_get_cart_url() code WC 10.3.6

function wc_get_cart_url() {
	global $post;

	// We don't use is_cart() here because that also checks for a defined constant. We are only interested in the page.
	if ( CartCheckoutUtils::is_cart_page() ) {
		$cart_url = get_permalink( $post->ID );
	} else {
		$cart_url = wc_get_page_permalink( 'cart' );
	}

	/**
	 * Filter the cart URL.
	 *
	 * @since 2.5.0
	 * @param string $cart_url Cart URL.
	 */
	return apply_filters( 'woocommerce_get_cart_url', $cart_url );
}