Search

WooCommerce Endpoints (2.1+)

WooCommerce 2.1 makes use of endpoints to show certain content to users on the frontend. This document explains what endpoints are, how we make use of them, how developers can use them, and what they replace when upgrading from WC 2.0.

What are endpoints? ↑ Back to Top

Endpoints are essentially just an extra part in the website URL which we detect and show different content when present. For example, you may have a ‘my account’ page shown on the URL yoursite.com/my-account. When the endpoint ‘edit-account’ is appended to this URL, making it ‘yoursite.com/my-account/edit-account‘ we will show the Edit account page instead of the My account page. Essentially this allows us to show different content without the need for multiple pages and shortcodes thus reducing the amount of content we need to install.

What endpoints replace from WC 2.0 ↑ Back to Top

In previous versions of WooCommerce pages and shortcodes were used instead for endpoint content. Examples of endpoints in WooCommerce include:

  • Edit account page (previously a page with the [woocommerce_edit_account] shortcode).
  • Edit address page (previously a page with the [woocommerce_edit_address] shortcode).
  • Change password page (previously a page with the [woocommerce_change_password] shortcode).
  • Lost password page (previously a page with the [woocommerce_lost_password] shortcode).
  • View order pages  (previously a page with the [woocommerce_view_order] shortcode).
  • Customer logout  (previously a page with the [woocommerce_logout] shortcode).
  • Checkout pay page  (previously a page with the [woocommerce_pay] shortcode).
  • Checkout thanks page  (previously a page with the [woocommerce_thankyou] shortcode).

If you are upgrading WooCommerce and wondering why these shortcodes no longer function its because they no longer exist. Although WooCommerce attempts to remove these pages during upgrade, if they have been customised they may not be removed.

It is safe to remove these pages after upgrading to WooCommerce 2.1

Why did you replace shortcodes with endpoints?

Quite simply; it makes installing WooCommerce easier and less prone to user error. With the pages and endpoints, we had to install the page, then set the content, then ensure WooCommerce knew where these pages were via setting. The risk would be that if a user edited one of these pages, or moved it, or deleted it, things could break. Endpoints remove that risk.

Account page endpoints ↑ Back to Top

The following endpoints are used for account related functionality and are appended to the URL of the my-account page:

  1. View order – /view-order/{ORDER_ID}
  2. Edit account (and change password – /edit-account/
  3. Edit address – /edit-address/{ADDRESS_TYPE}
  4. Lost password – /lost-password/
  5. Logout – /customer-logout/

Checkout page endpoints ↑ Back to Top

The following endpoints are used for checkout related functionality and are appended to the URL of the checkout page:

  1. Pay page – /order-pay/{ORDER_ID}
  2. Order received (thanks) – /order-received/
  3. Add payment method – /add-payment-method/

Customising endpoint URLs ↑ Back to Top

The URL for each endpoint can be customised from the settings. For account endpoints you can go to WooCommerce > Settings > Accounts and edit the endpoint settings:

2014-02-26 at 14.19

For checkout endpoints you can go to WooCommerce > Settings > Checkout and modify them:

2014-02-26 at 14.20

Ensure they are unique to avoid conflicts, and if you run into issues with 404’s go to Settings > Permalinks and save to flush the rewrite rules.

Using endpoints in menus ↑ Back to Top

If you want to include an endpoint in your menus, where previously you could drag the page into the menu, now you need to use the ‘links’ section:

2014-02-26 at 14.26

Enter the full URL to the endpoint and then insert that into your menu. Remember: some endpoints such as view-order require an order ID to work – we don’t recommend adding these endpoints to your menus. Those pages can instead be accessed via the my-account page.

Using endpoints in Payment Gateway Plugins ↑ Back to Top

Where previously developers would be able to use get_permalink for the URL of the pay and thanks pages, they should now be using the endpoints. Thankfully, WooCommerce provides to helper functions in the order’s class for getting these URLs. They are:

$order->get_checkout_payment_url( $on_checkout = false );

and:

$order->get_checkout_order_received_url();

Gateways need to use these methods for full 2.1 compatibility.

Troubleshooting ↑ Back to Top

Endpoints showing 404

1. If you are seeing a 404 error (after upgrading perhaps) go to Settings > Permalinks from your WordPress dashboard and ‘save’. This will ensure the rewrite rules for the endpoints exist and are ready to be used.

2. If using an end point such as ‘view-order’ ensure it specifies an order number. /view-order/ is invalid. /view-order/10/ is valid. These types of endpoint shouldn’t be in your navigation menus.

Back to the top