In a WordPress template, how can I detect if the current page is the WooCommerce cart or checkout page?

Solution:

Cart page

is_cart()

Returns true on the cart page.

Checkout page

is_checkout()

Returns true on the checkout page.

You can see more about WooCommerce conditional tags