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.
Great stuff