Blog

How to Get Various WooCommerce Page URLs

Shop URL

Get the WooCommerce Shop URL (this is the root category page) with the following:

$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );

My Account URL

You can get the WooCommerce My Account URL by using the woocommerce_myaccount_page_id option:

$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
if ( $myaccount_page_id ) {
  $myaccount_page_url = get_permalink( $myaccount_page_id );
}

Cart URL

The WooCommerce Cart URL can be retrieved with a call to the cart object’s get_cart_url() method:

global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();

Checkout URL

Similar to getting the cart URL, the WooCommerce Checkout URL can be retrieved with a call to the cart object’s get_checkout_url() method:

global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();

Payment Page URL

This is the payment page URL used to collect payment information after the checkout page by redirect/hosted payment gateways. The path typically looks like /checkout/pay/. Get this URL with the following:

$payment_page = get_permalink( woocommerce_get_page_id( 'pay' ) );

// make ssl if needed
if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' ) $payment_page = str_replace( 'http:', 'https:', $payment_page );

Logout URL

This example will generate a WordPress logout URL that brings the user back to the Account area of the site:

$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );

if ( $myaccount_page_id ) {

  $logout_url = wp_logout_url( get_permalink( $myaccount_page_id ) );

  if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' )
    $logout_url = str_replace( 'http:', 'https:', $logout_url );
}

27 Comments

  • rashed 4 years ago

    how to find track my order page url??

    • Justin Stern 4 years ago

      Hey rashed, good question. Actually I don’t think there’s a programmatic way of retrieving the url for the “track my order” page, just because it’s not one of the special WooCommerce pages, it’s handled by the shortcode [woocommerce_order_tracking] so you can just go to your WordPress admin Pages area and find/create the page. Hope this helps

  • JMichael 4 years ago

    Good stuff!

  • capitalH 4 years ago

    Nice, Very useful. Thanks

  • Mariz Papas 4 years ago

    Hi Justin,

    Good day!

    What page of woocommerce can I see this code? Since I’ll be changing the URL for the Logout to Shopping page. Thanks for the tutorial. I am hoping for your kind response soon.

    Thanks and have a great day ahead.

    Best regards,
    Mariz

    • Max Rice 4 years ago

      Try the WooCommerce > Settings > Pages page 🙂

  • João Gabriel G Marques 4 years ago

    Hi, great post !! I would like to know how to get the url for page “My Orders”, I’m not sure if there is a specific page for the customers which shows their orders.

    Thanks!

    • Max Rice 4 years ago

      The “My Recent Orders” section is on the “My Account” page, so you can use the my account code above to get the URL 🙂

  • vishal 3 years ago

    Hello can i change WooCommerce url like this ?
    Is this recommended if yes how i can do this?

    Cateogry:
    product-category/ to say: /category/

    Shop by category:
    shop-by-category/ to /shop/

    • Max Rice 3 years ago

      Yep, on the Settings > Permalink menu 🙂

  • Joe 3 years ago

    Very useful. Is there a way to fix the permalinks if they’re incorrect? I migrated a copy of a client’s site to my local machine, but the links for My Account and Checkout are incorrect, yet all the places where you can set the site’s address are correct.

  • Paul 3 years ago

    Hello.
    How can I change default shop url from http://www.mydomain.com/shop to http://www.mydomain.com/
    Thanx

    • Max Rice 3 years ago

      Try to change Settings > Reading > Front Page to “Shop” 🙂

  • Christopher 3 years ago

    Thanks, you can also use the following:

    woocommerce_get_page_id( ‘cart’ );
    woocommerce_get_page_id( ‘change_password’ );
    woocommerce_get_page_id( ‘checkout’ );
    woocommerce_get_page_id( ‘edit_address’ );
    woocommerce_get_page_id( ‘logout’ );
    woocommerce_get_page_id( ‘lost_password’ );
    woocommerce_get_page_id( ‘myaccount’ );
    woocommerce_get_page_id( ‘pay’ );
    woocommerce_get_page_id( ‘view_order’ );
    woocommerce_get_page_id( ‘shop’ );
    woocommerce_get_page_id( ‘terms’ );
    woocommerce_get_page_id( ‘thanks’ );

  • Parhum 3 years ago

    Thanks, it’s very useful for me 🙂

  • Ricard Torres 3 years ago

    Thanks for sharing it, that first link to the shop was exactly what I needed.

    Cheers.

  • mary 3 years ago

    Thank you for all the great info Justin!
    Is there an easy way to redirect to a web address after checkout?

    • Beka Rice 3 years ago

      Do you mean an external page, or just another page on your site? I’d recommend using the ‘Thank you’ page right after checkout, as a lot of plugins use this page for tracking and to fire various other scripts.

  • Jeff 3 years ago

    How do I insert another URL?

    woocommerce_get_page_id( ‘URL’ );

  • Andrew 3 years ago

    Great info, thank you.

    How would I get to the Woocommerce URL for http://yoursite.com/checkout/shipping-addresses/ found in the Woocommerce Multiple Shipping Address add-on?

    Thank you!

  • Capp 3 years ago

    Hi, is there an url where I can automatically download new orders on my pc?

    • Beka Rice 3 years ago

      Hey there, to get orders out of WooCommerce you’d have to use an exporter, such as the CSV Order export (gives you an Excel file).

  • jagdeep 2 years ago

    How to get the single product page url in Woocommerce?.

    • Beka Rice 2 years ago

      Since you’ll be getting a URL for a particular product, you can get the permalink based on the page/post id using get_permalink.

  • Ken Siosan 2 years ago

    Saves my day, thanks 🙂

  • Prafulla Kumar Sahu 2 years ago

    I want user to redirected to checkout page if cart contains a certain category of product , can you lease help me ?

Hmm looks like this article is over 2 years old! Its content may be outdated, so comments are now closed.