How to get the checkout object in Woocommerce custom template

Viewed 479

For WooCommerce I create an own checkout page but I have an Issue.

The code $checkout->get_value( 'billing_first_name' ); does not work in my template file.

My file is called with `get_template_part( 'temp-parts/content/pages/checkout-billing'); in the file woocommerce/checkout/form-billing.php

This generate an error

Call to a member function get_value() on null

If I use this code directly in the file woocommerce/checkout/form-billing.php the code does work.

Is it possible to get the checkout information in my own template?

2 Answers

As $checkout variable is not defined, you should use instead:

WC()->checkout->get_value( 'billing_first_name' );

Now it will work.

Use global $woocommerce and after that $woocommerce->checkout->get_value( 'billing_first_name' );

Related