Menu Close

WooCommerce: Easily Get Cart, Checkout, Account, Product URLs

default

Just so you know, there is no need to hardcode WooCommerce URLs in your custom code! In fact, WooCommerce gives us helpful shortcut functions that we can reuse in our code to get cart, checkout, account and product URLs without wondering if they have been modified by the website owner e.g. example.com/cart to example.com/basket.

In this way, you can always make sure you’re getting the correct URLs without wasting time looking for page/product slugs. Enjoy!

No need to hardcode “https://——-.h4.conves.io/cart/” in my custom WooCommerce code… I can just use wc_get_cart_url()! Find more shortcuts below.

WooCommerce Product URL

/* On a single product page */
get_the_permalink()

/* If you have the product ID */
get_permalink( $product_id )

/* If you have the $product object */
$product->get_permalink()

WooCommerce Cart URL

wc_get_cart_url()

WooCommerce Checkout URL

wc_get_checkout_url()

WooCommerce Shop URL

wc_get_page_permalink( 'shop' )

WooCommerce My Account URLs

/* My Account Page */
wc_get_page_permalink( 'myaccount' );

/* My Account Endpoints */
wc_get_account_endpoint_url( 'edit-address' );
wc_get_account_endpoint_url( 'edit-account' );
wc_get_account_endpoint_url( 'payment-methods' );
wc_get_account_endpoint_url( 'lost-password' );
wc_get_account_endpoint_url( 'customer-logout' );
wc_get_account_endpoint_url( 'dashboard' );
// ETC.

WooCommerce Product Category / Product Tag URL

get_term_link( 'tables', 'product_cat' )
get_term_link( 'mixed', 'product_tag' )

WooCommerce Thank You Page URL

wc_get_endpoint_url( 'order-received', $order_id, wc_get_checkout_url() )
View Source
Posted in WooCommerce Tips