How to get WooCommerce page URLs in WooCommerce 3.x

How to get WooCommerce page URLs in WooCommerce 3.x

WooCommerce introduced a function which makes things much more elegant and simple, and gets rid of global $woocommerce and $aUrl when getting page URLs.

So, if you want to create a built-in custom menu for your theme or just need the WooCommerce pages URLs for other purposes, there’s a simple solution: the wc_get_page_id function.

The function can be used for getting the page URL for myaccount, edit_address, shop, cart, checkout, pay, view_order, and terms. It will return -1 if no page is found.

Examples of usage:

Get and display the My Account page url

<?php echo get_permalink( wc_get_page_id( 'myaccount' ) ); ?>

Get and display the Shop page url

<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>

Get and display the Cart page url

<?php echo get_permalink( wc_get_page_id( 'cart' ) ); ?>

Get and display the Checkout page url

<?php echo get_permalink( wc_get_page_id( 'checkout' ) ); ?>

Change the function’s argument as needed for the other pages.

Leave a Reply

Get your fix of
all cool things WordPress

DigitalOcean hosting coupon 10$ coupon

for DigitalOcean hosting.
Sammy-approved.

Get this deal