Skip to content
All writing

How to get WooCommerce default URLs with PHP functions

Get the WooCommerce cart, checkout, account, and shop URLs with built-in PHP functions instead of hardcoding them.

#snippetswordpressphpwoocommerce

Don't hardcode /cart or /checkout. Store owners rename those pages, and translation plugins change them per language. WooCommerce already knows the right URL.

Cart URL

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

Checkout URL

<a href="<?php echo esc_url( wc_get_checkout_url() ); ?>">Checkout</a>

My account URL

<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>">My account</a>

Shop URL

<a href="<?php echo esc_url( wc_get_page_permalink( 'shop' ) ); ?>">Back to shop</a>

Get new posts by email

New writing in your inbox. Unsubscribe anytime.