Home / Blog / Code Snippets
,

How to get various URL of all WooCommerce pages?

WooCommerce, the best WordPress plugin, and most customizable eCommerce
a platform for building your online business. WooCommerce provides flexibility to customize its default functionality and create your shop design as you want. You might sometimes want to display WooCommerce page links on the website.

To get the URLs of all WooCommerce pages and display links on your website, you can use the below code on your website.

1. Using wc_get_page_permalink() (Recommended)

// Shop page
$shop_url = wc_get_page_permalink( 'shop' );

// Cart page
$cart_url = wc_get_page_permalink( 'cart' );

// Checkout page
$checkout_url = wc_get_page_permalink( 'checkout' );

// My Account page
$myaccount_url = wc_get_page_permalink( 'myaccount' );

// Terms & Conditions page
$terms_url = wc_get_page_permalink( 'terms' );

2. Using WooCommerce Helper Functions

$shop_url       = get_permalink( wc_get_page_id( 'shop' ) );
$cart_url       = wc_get_cart_url();
$checkout_url   = wc_get_checkout_url();
$myaccount_url  = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) );

3. Using get_option() with Page IDs

$shop_page_id       = get_option( 'woocommerce_shop_page_id' );
$cart_page_id       = get_option( 'woocommerce_cart_page_id' );
$checkout_page_id   = get_option( 'woocommerce_checkout_page_id' );
$myaccount_page_id  = get_option( 'woocommerce_myaccount_page_id' );
$terms_page_id      = get_option( 'woocommerce_terms_page_id' );

// Convert ID to URL
$shop_url = get_permalink( $shop_page_id );

4. Get All WooCommerce Page URLs at Once

function get_all_woocommerce_page_urls() {
    $wc_pages = [
        'shop'      => wc_get_page_permalink( 'shop' ),
        'cart'      => wc_get_page_permalink( 'cart' ),
        'checkout'  => wc_get_page_permalink( 'checkout' ),
        'myaccount' => wc_get_page_permalink( 'myaccount' ),
        'terms'     => wc_get_page_permalink( 'terms' ),
    ];

    return $wc_pages;
}

$urls = get_all_woocommerce_page_urls();

foreach ( $urls as $page => $url ) {
    echo esc_html( $page ) . ': ' . esc_url( $url ) . '<br>';
}

5. My Account Endpoint URLs

For sub-pages inside My Account, use wc_get_account_endpoint_url():

$orders_url    = wc_get_account_endpoint_url( 'orders' );
$downloads_url = wc_get_account_endpoint_url( 'downloads' );
$address_url   = wc_get_account_endpoint_url( 'edit-address' );
$account_url   = wc_get_account_endpoint_url( 'edit-account' );
$logout_url    = wc_get_account_endpoint_url( 'customer-logout' );

Want this checked on your own site? See Exivon Tech’s Website & E-commerce Audit.

Dhiren Patel

Principal Full-Stack Engineer · Founder, Exivon Tech

I’ve built and run enterprise web platforms and e-commerce for 13 years, and I built ShieldScope, a free WordPress security scanner.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.