Code Snippet For Various WooCommerce Page URLs

Share Now

1. Shop URL

Get the WooCommerce Shop URL (this is the root category page) with the following:

$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );

2. My Account URL

Get the WooCommerce Shop URL (this is the root category page) with the following:

<?php if ( is_user_logged_in() ): ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" class="user-login-btn" title="<?php _e('My Account','your_theme_name'); ?>">My Account</a>
<?php endif;?>

3. My Account URL

Get the WooCommerce Shop URL (this is the root category page) with the following:

<?php if ( is_user_logged_in() ): ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" class="user-login-btn" title="<?php _e('My Account','your_theme_name'); ?>">My Account</a>
<?php endif;?>

4. Cart URL

Call the cart object’s get_cart_url() method in order to get the WooCommerce cart page url:

global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();

5. Checkout URL

Call the cart object’s get_checkout_url() method in order to get the WooCommerce Checkout page url:

global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();

6. Payment Page URL

$payment_page = get_permalink( woocommerce_get_page_id( 'pay' ) );

// make ssl if needed
if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' ) $payment_page = str_replace( 'http:', 'https:', $payment_page );

7. Logout URL

<a href="<?php echo wp_logout_url( get_permalink() ); ?>" class="user-register-btn">Log Out</a>
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert