When customizing WooCommerce checkout page, you may want to get the checkout URL to create a redirect after WooCommerce checkout or to customize the checkout URL. You may also want to save the WooCommerce checkout URL as a variable to later pass it to your functions and so on.
In this case you need to know how to quickly get checkout URL in your code. In this simple and straightforward tutorial, I will show you how you can get the checkout URL with an code snippet and an example.
WooCommerce Get Checkout URL
From the global $woocommerce object you can get the checkout URL. This can be done using the avaialble function that allows users to get checkout URL.
The WooCommerce checkout URL can be pulled with a call to the cart object’s get_checkout_url() method. To get the checkout URL we need to access the global $woocommerce object.
If you do not declare the global object then we would be not able to get WooCommerce checkout URL. Secondly, we need to use the WooCommerce function wc_get_checkout_url() which is introduced after WooCommerce version 2.5.
global $woocommerce;
$checkout_page_url = function_exists( 'wc_get_cart_url' ) ?
wc_get_checkout_url() : $woocommerce->cart->get_checkout_url();
Note: The get_checkout_url() cart object method has been deprecated since WooCommerce 2.5.
3.2 From the WooCommerce and WordPress function
$checkout_page_id = wc_get_page_id( 'checkout' );
$checkout_page_url = $checkout_page_id ? get_permalink( $checkout_page_id ) : '';
Conclusion
In this post, we have looked at how to get checkout URL, using the code snippet shared above. You can implement this code in your WooCommerce theme or plugin. If you need further assistance, feel free to get in touch with me.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- WooCommerce Difference Between PayPal and PayPal Checkout
- How to Add Date Field to Checkout In WooCommerce
- How to Add Select Field to Checkout WooCommerce
- How to Change WooCommerce Checkout Error Messages
- How to Get WooCommerce Checkout Country Dropdown
- How to Remove Hash # from WordPress URLs with Simple Trick
- How to Get Order Details After Checkout In WooCommerce
- How to Hide Tax Label In WooCommerce
- How to Hide Price If Zero In WooCommerce
- How to Hide Weight of Product in WooCommerce
- WooCommerce Mobile Checkout Optimization Quick Guide
- How Get Product ID on Checkout Page Or Order Page In WooCommerce
- How to Change Checkout Endpoints WooCommerce
- How to Remove Phone Number Field From Checkout WooCommerce
- How to Hide Errors From Visitors WooCommerce
- How to Get Order ID on Checkout Page WooCommerce
- How to Hide Shipping Methods for Certain Conditions
- How to Hide Company Name Field WooCommerce Checkout Page
- How to Hide Price When Out of Stock In WooCommerce