Enjoy Up To
80% OFF

How to get WooCommerce Pages URL programmatically

How to get WooCommerce Pages URL programmatically

Are you trying to figure out how to obtain the WooCommerce Pages URL? Do you want to make a change? You’ve arrived at the right location. We’ll teach you how to access the WooCommerce Shop URL programmatically and how to modify it to get the most out of it in this post.

The Default WooCommerce Shop Page URL

The default shop page on a WooCommerce online store is the website URL with a slash and the string “shop,” as you may know. For instance, https://nextwoo.themedev.net/shop That’s why, in most circumstances, determining the shop URL of an eCommerce store created with WooCommerce is simple.

In the backend, go to WooCommerce > Settings > Products in your dashboard to locate the shop URL.

The Advanced tab is also where you’ll discover the remainder of WooCommerce’s pages, such as cart, checkout, my account, and terms & conditions.

As you can see, all you have to do to find your WooCommerce store’s shop URL is go to the settings page in the admin dashboard. But what if you need to get the URL in order to create a link or do some type of code validation?

We’ll show you how to access the shop URL programmatically in the next part, as well as some other helpful hints.

How to Get the WooCommerce shop URL?

First, let’s see how to get the shop URL in WooCommerce. With the following snippet, you’ll get the base shop for your website:

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

To print the URL on the front end, you can use a hook. If you’re not familiar with hooks, we highly recommend you have a look at this guide.

In this example, we’ll use the wp_header hook so the URL will be printed above the header.

    $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
    echo $shop_page_url;

Now that you got your shop URL, let’s see different examples to customize it.

NOTE: To test all of the following scripts, we recommend using the obtain shop URL sample script.

How to change the WooCommerce Shop URL?

We’ll show you how to update the base shop URL in WooCommerce in this section. To do so, you’ll need to start by creating a new page on which the shop will be printed.

Go to Pages > Add New in your WooCommerce dashboard, create an empty page, and give it a name. After that, go to the WooCommerce Settings page and select your newly created page from the Shop Page menu. We’ve established a new page called Store in this example.

That concludes our discussion. Your Shop page will be the new page you built from now on. This new base store URL will print all of the products in the same way that the default shop page does.

Similarly, the Advanced tab allows you to edit the cart, checkout, My Account, and Terms & Conditions pages.

How customize WooCommerce Pages by Plugin?

NextWoo provides the services to build WooCommerce templates with its editor flexibility for Elementor & Gutenberg. Multi-designed WooCommerce single product layout builder – NextWoo

NextWoo is a WooCommerce Builder to build a Single Product, Cart, Checkout, My Account, Shop Loop, related products, Quick view, Up-sell, Cross sale, and so on by Elementor or Gutenberg.

Elementor is a popular WordPress page builder plugin. It lets you easily create custom layouts for your WordPress pages with a drag & drop interface.

Extraordinary Features of NextWoo:

1.  Create unlimited templates for woo customization

You can create unlimited templates for Single Products, Shop layout, Archive Layout, Checkout, My Account, Cart, Related products, and more WooCommerce pages.

2.  Set preset woo templates by onclick

With a single click, you can set Woo layout templates from pre-build designs. It will surely save you time.

3.  Build templates with Elementor & Gutenberg

NextWoo offers Elementor & Gutenberg to build or customize beautiful woo templates, there are 100+ Widgets and Blocks are available for both Elementor & Gutenberg editors.                       

4.  Supports multiple product type

Easily build variable, grouped, subscription, and simple products layout using Elementor | Gutenberg Widgets.

5.  Construct versatile shop page templates

Use the Shop widgets to craft a decent template that presents all products in the best light. Get extra features:  AJAX add to cart method, Quick View, Compare Button, Wishlist, Image Slider, and so no

6.  Custom Checkout page template

Form a beautiful checkout page that is fully covered with order review, billing, shipping, and payments information.

7.  Built with Success template

Build and apply a Thank You page to complete the purchasing process that contains the following formalities like order details, order, Customer Address Details, and more.

8.  Customize quick view template

Create a customizable Quick View page to see the short information of products.

How to get WooCommerce pages URL?

We just learned how to retrieve the WooCommerce shop URL and alter it. Let’s look at how to acquire the URLs of other pages programmatically so you can use them in your scripts.

Get checkout URL

To get the checkout URL programmatically, you can use the wc_get_checkout_url() function:

$checkout_page = wc_get_checkout_url();

For more ideas on how to customize your checkout, have a look at this full guide.

Find My Account URL

To get the “My Account” page URL, you can use the get_permalink() function again like this:

$account= get_permalink( wc_get_page_id( 'myaccount' ) );

The My Account page is often disregarded, yet it has the potential to improve your customers’ experience. Check out our WooCommerce My Account Page tutorial for more information on how to make the most of it.

Get Cart URL

Similarly, you can get the cart URL using the get_permalink() function:

$cart= get_permalink( wc_get_page_id( 'cart' ) );

Customize the Return to Shop URL

Now let’s have a look at a slightly more complex example. Let’s see how to customize the Return to Shop URL. The Return to Shop URL is the link or button that you see when the shop is empty.

By default, that link or button redirects to the shop page, but you can change the URL to redirect people to any website you like.

For example, if you want to redirect people to the home page by changing the URL of the Return to shop link on the cart page, use the following script:

add_filter( 'woocommerce_return_to_shop_redirect', 'QuadLayers_change_return_shop_url' );
function QuadLayers_change_return_shop_url() {
    return home_url();

We’re using the home_url() function to redirect to the home page, but you can change the return line to any custom URL you like. Return ‘https://www.yourdomain.com/blog’ in the return line, for example, to redirect people to your blog page.

WooCommerce endpoints

We’re using the home_url() function to redirect to the home page, but you can change the return line to any custom URL you like. Return ‘https://www.yourdomain.com/blog‘ in the return line, for example, to redirect people to your blog page.

These endpoints are associated with orders or accounts, and they will display specific material that is only available when an order is placed or when a user logs in. Users will be redirected to the home page if those things do not occur.

Find Payment page URL

This will work only if the user has added a product to the cart since it needs an existing order to reach the payment endpoint successfully.

$t=new WC_order;

$payment_page = $t->get_checkout_payment_url();

Get a product URL using its ID

You can get any product URL using its ID and the get_permalink() function as follows

$product_url = get_permalink($product_id);

Alternatively, you can use the name of a product (WordPress Pennant):

$product = get_page_by_title( 'WordPress Pennant', OBJECT, 'product' );

$producturl = get_permalink($product->ID);

Get home URL

As its name suggests, the home_url(); the function will return the URL of the website’s home page.

$home_page = home_url();


In conclusion, you can quickly obtain your store’s shop URL via the WooCommerce dashboard. If you need to retrieve the URL, though, you’ll need to use some code.

We’ve seen how to acquire the WooCommerce shop URL programmatically in this guide. You’ve also learned how to update the shop’s URL and get the URLs for additional pages. Finally, we’ve given you a quick rundown of how to personalize your Shop Page to get the most out of it.

Was this tutorial helpful to you? Is there anything more you’d like us to write for you? Please let us know in the comments section below!

Golam Mostafa
Written by

Golam Mostafa

I'm a senior plugin developer of WordPress. I have four years of experience working as a software engineer with ADB Bank, and in 2018, I started developing plugins and founded ThemeDev.

Table of Content

Table of Contents