Call
608.845.2900
Visit
330 Locust Dr.
Verona, WI 53593
Message
info@powderkegwebdesign.com
Powderkeg Web Design
Menu
Message Us
Matt
Matt

Woocommerce Custom Single Page Checkout

July 29, 2016

By default, Woocommerce’s checkout process is broken into two parts. The shopping cart page and the actual checkout page. With a few tweaks, we can combine these two and make ordering on your site even easier.

If you want all default functionality across the board, getting single/one-page checkout is super simple. All you need to do is call the two Woocommerce shortcodes in your page content and you’re good to go.

[woocommerce_cart]
[woocommerce_checkout]

If we’re doing some more complex things with our templates, we’re going to need to do a little bit more work. Having those two shortcodes in our content area causes Woocommerce to always return true when figuring out if the current page we are on is a checkout page or if the current page is the cart page. In our case, we want it to be both.

Having [woocommerce_cart] in our content returns true for the is_cart() function.
Having [woocommerce_checkout] in our content returns true for the is_checkout() function.

When those two shortcodes aren’t present in our content we need to manually set some variables to make those functions return true.

For is_cart() to return true, we can set a global constant of WOOCOMMERCE_CART to true.
For is_checkout() to return true, we can add a filter for the hook woocommerce_is_checkout to return true.

As some plugins and other Woocommerce add-ons enqueue scripts in the wp_head hook, we need to set those constants are early as we can. Through trial and error, I’ve found that the best place to do it is on the wp hook. To determine what pages to set the constants on, I’m doing some checks on the template name.

Add that to your functions.php file and update the template names to your templates and you’re all set to go!

Matt
Matt
Technical Account Manager

Matt is a skilled and nimble programmer that assists the entire team wherever help is needed. He has exceptional troubleshooting skills, is an extremely fast coder, and has strong database skills.