How to Get WooCommerce Page URLs in PHP

Quick Summary
- Use wc_get_page_permalink( 'shop' ) or ( 'myaccount' ), wc_get_cart_url() and wc_get_checkout_url(); they read the pages set in the WooCommerce settings.
- For My Account sections use wc_get_account_endpoint_url( 'orders' ) and similar keys; order links come from get_checkout_payment_url() and get_view_order_url().
- woocommerce_get_page_id() and the cart's get_cart_url() and get_checkout_url() still run in WooCommerce 11 but are deprecated since 3.0 and 2.5.
To get a WooCommerce page URL in PHP, use WooCommerce’s own functions: wc_get_page_permalink( 'shop' ) for the shop, wc_get_cart_url() for the cart, wc_get_checkout_url() for the checkout and wc_get_page_permalink( 'myaccount' ) for My Account. For a section of My Account, such as Orders, use wc_get_account_endpoint_url( 'orders' ). These functions read the pages chosen in the WooCommerce settings, so they keep working when a page is renamed, and they work the same in classic and block themes.
Older snippets use woocommerce_get_page_id() and the cart’s get_cart_url() and get_checkout_url() methods. WooCommerce 11 still runs them, but they are deprecated and print deprecation notices when debugging is on. The sections below show the current way for each page.
All the main URLs at once
$shop_url = wc_get_page_permalink( 'shop' );
$cart_url = wc_get_cart_url();
$checkout_url = wc_get_checkout_url();
$account_url = wc_get_page_permalink( 'myaccount' );
$orders_url = wc_get_account_endpoint_url( 'orders' );Each one returns the full URL as a string, for example https://example.com/cart/ for the cart. Print them with esc_url(), as in the My Account example below.
Shop page URL
wc_get_page_permalink( 'shop' ) returns the URL of the page chosen as Shop page in WooCommerce > Settings > Products. The same function takes 'cart', 'checkout', 'myaccount' and 'terms' for the other pages WooCommerce keeps in its settings.
If no shop page is set, it returns your home page URL instead. Pass false as the second argument when you’d rather get false and handle that case yourself:
$shop_url = wc_get_page_permalink( 'shop', false );
if ( $shop_url ) {
echo '<a href="' . esc_url( $shop_url ) . '">Shop</a>';
}The older form, get_permalink( woocommerce_get_page_id( 'shop' ) ), has been deprecated since WooCommerce 3.0. If you need the page ID itself, for example to compare it with the current page, use wc_get_page_id( 'shop' ). It returns -1 when no page is set, so get_permalink( wc_get_page_id( 'shop' ) ) returns false in that case.
Cart and checkout URLs
wc_get_cart_url() and wc_get_checkout_url() return the URLs of the pages set as Cart page and Checkout page in WooCommerce > Settings > Advanced > Page setup. They replace the cart object’s get_cart_url() and get_checkout_url() methods, which have been deprecated since WooCommerce 2.5, and they don’t need global $woocommerce.
Since WooCommerce 9.3, when wc_get_cart_url() is called on the Cart page, or on another page that contains the classic cart shortcode, it returns that page’s URL. Both URLs can be changed by plugins through the woocommerce_get_cart_url and woocommerce_get_checkout_url filters, which is another reason to use the functions instead of building the URL yourself.
My Account URL
wc_get_page_permalink( 'myaccount' ) returns the My Account page URL. This example prints it as a link for logged-in users only:
<?php if ( is_user_logged_in() ) : ?>
<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="user-login-btn"><?php esc_html_e( 'My Account', 'your_theme_name' ); ?></a>
<?php endif; ?>WooCommerce saves the page ID in the woocommerce_myaccount_page_id option, so get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) gives the same URL. The WooCommerce function is shorter, and it also applies WooCommerce’s page filters.
My Account section URLs
The Orders, Downloads, Addresses, Payment methods and Account details sections of My Account are endpoints, not separate pages. wc_get_account_endpoint_url() builds their URLs:
$orders_url = wc_get_account_endpoint_url( 'orders' );
$address_url = wc_get_account_endpoint_url( 'edit-address' );
$details_url = wc_get_account_endpoint_url( 'edit-account' );
$logout_url = wc_get_account_endpoint_url( 'customer-logout' );
$dashboard_url = wc_get_account_endpoint_url( 'dashboard' ); // The My Account page itself.- Pass the endpoint’s key, not its slug. If you renamed the Orders endpoint to
my-ordersin WooCommerce > Settings > Advanced > Account endpoints,wc_get_account_endpoint_url( 'orders' )returns/my-account/my-orders/. - The other section keys are
downloadsandpayment-methods. - The
customer-logoutURL includes a security nonce, so the customer is logged out straight away. Without the nonce, WooCommerce asks “Are you sure you want to log out?” first; see skipping WooCommerce’s log out confirmation. - For the page of one order in My Account, use
$order->get_view_order_url().
Order payment and order received URLs
Very old themes used a separate Pay page, with get_permalink( woocommerce_get_page_id( 'pay' ) ). Since WooCommerce 2.1, customers pay on the order-pay endpoint of the checkout page, and the order received page is an endpoint too. In WooCommerce 11 that old code returns the checkout page URL and triggers two deprecation notices.
Get the links from the order instead:
$order = wc_get_order( $order_id );
if ( $order ) {
$pay_url = $order->get_checkout_payment_url();
$received_url = $order->get_checkout_order_received_url();
}get_checkout_payment_url() returns the link a customer uses to pay for a pending order, with the order key in the URL. get_checkout_order_received_url() returns the order confirmation (thank you) page for that order.
Logout URL
wp_logout_url() returns a logout link that includes a security nonce. Passing get_permalink() sends the customer back to the current page after logging out.
<a href="<?php echo wp_logout_url( get_permalink() ); ?>" class="user-register-btn">Log Out</a>WooCommerce’s wc_logout_url() does the same but sends customers to the My Account page by default. Both return the URL already escaped for HTML (with & between the parameters), so print it in an href as it is.
Frequently asked questions
Why does wc_get_page_permalink() return my home page URL?
The page isn’t set in the WooCommerce settings, or the page it points to was deleted. Choose the page again under Products > Shop page or Advanced > Page setup. Since WooCommerce 3.4, the second argument lets you choose a different fallback than the home page.
Do these functions work with the Cart and Checkout blocks?
Yes. The blocks sit on the pages set as Cart page and Checkout page, and the functions only read those settings, so they return the same URLs whether a page uses the blocks or the classic shortcodes.
Why does my theme break when WooCommerce is deactivated?
These functions only exist while WooCommerce is active. In theme templates, wrap the code in if ( function_exists( 'wc_get_cart_url' ) ) or a similar check, so the site doesn’t show a fatal error when the plugin is off.
Related articles
- more WooCommerce snippets for custom themes: prices in a loop, cart count and account links
- a header cart count that updates with AJAX: pairs with a cart link in the header
- skipping WooCommerce’s log out confirmation: for customers logging out from the My Account menu
