WooCommerce reviews + tutorials

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 );
}

Published by Justin Stern

Justin is one of our co-founders, and is our resident overengineer. He likes to write developer tutorials and make black magic happen in our plugins. He thinks that writing code is a lot easier than writing words.

27 Comments

  1. Avatar

    how to find track my order page url??

    • Avatar

      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

  2. Avatar

    Good stuff!

  3. Avatar

    Nice, Very useful. Thanks

  4. Avatar

    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

  5. Avatar

    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!

    • Avatar

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

  6. Avatar

    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/

  7. Avatar

    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.

  8. Avatar

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

  9. Avatar

    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’ );

  10. Avatar

    Thanks, it’s very useful for me 🙂

  11. Avatar

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

    Cheers.

  12. Avatar

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

    • Avatar

      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.

  13. Avatar

    How do I insert another URL?

    woocommerce_get_page_id( ‘URL’ );

  14. Avatar

    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!

  15. Avatar

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

  16. Avatar

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

  17. Avatar

    Saves my day, thanks 🙂

  18. Avatar

    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 quite old! Its content may be outdated, so comments are now closed.