How to Check If It Is Checkout Page WooCommerce

Is Checkout Page WooCommerceIf you are looking for a quick way on how to know if the instance is checkout page WooCommerce, this is the tutorial for you. Ideally, you can check if you are on the checkout page to execute a certain condition that should be done when the user is on the checkout page. The best way to check if the user is on the checkout page you can make use of the URL parameters.

Is Checkout Page WooCommerce

To check if it is the checkout page in WooCommerce you can use the template code that is a conditional tag just like any other conditional tag

is_checkout()Returns true on the checkout page

This conditional tag allows you to know if you are on the checkout page. The following is a code snippet that uses this template tag :

if ( is_checkout() ) {

    echo 'It is checkout page';

}

You can also go ahead and use the function to check the endpoint as shown in the code samples below :

is_wc_endpoint_url()Returns true when viewing a WooCommerce endpoint

is_wc_endpoint_url( 'order-pay' )When the endpoint page for order pay is being displayed.

is_wc_endpoint_url( 'order-received' )When the endpoint page for order received is being displayed

.is_wc_endpoint_url( 'view-order' )When the endpoint page for view order is being displayed.

is_wc_endpoint_url( 'edit-account' )When the endpoint page for edit account is being displayed.

is_wc_endpoint_url( 'edit-address' )When the endpoint page for edit address is being displayed.

is_wc_endpoint_url( 'lost-password' )When the endpoint page for lost password is being displayed.

is_wc_endpoint_url( 'customer-logout' )When the endpoint page for customer logout is being displayed.

is_wc_endpoint_url( 'add-payment-method' )When the endpoint page for add payment method is being displayed.

You can use the function above to get the order ID as in the code snippet below :

 if ( is_wc_endpoint_url( 'order-received' ) ) {

          global $wp;

           //Get Order ID 
         $order_id =  intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
                        
             
    }

Conclusion

In this tutorial, we have highlighted how you can check if the user is on the checkout page using the conditional function that allows you to check if you are on the checkout page.

Similar Articles