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.

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

Get and display the Shop page url

Get and display the Cart page url

Get and display the Checkout page url

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

One comment

Leave a Reply

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