WooCommerce Code Reference

WC_Checkout
in package

Checkout class.

Table of Contents

$fields  : array|null
Checkout fields are stored here.
$instance  : WC_Checkout|null
The single instance of the class.
$legacy_posted_data  : array
Holds posted data for backwards compatibility.
$logged_in_customer  : WC_Customer
Caches customer object.
__clone()  : mixed
Cloning is forbidden.
__get()  : array|string
Gets the legacy public variables for backwards compatibility.
__isset()  : bool
See if variable is set. Used to support legacy public variables which are no longer defined.
__set()  : mixed
Sets the legacy public variables for backwards compatibility.
__wakeup()  : mixed
Unserializing instances of this class is forbidden.
check_cart_items()  : mixed
When we process the checkout, lets ensure cart items are rechecked to prevent checkout.
checkout_form_billing()  : mixed
Output the billing form.
checkout_form_shipping()  : mixed
Output the shipping form.
create_order()  : int|WP_ERROR
Create an order. Error codes: 520 - Cannot insert order into the database.
create_order_coupon_lines()  : mixed
Add coupon lines to the order.
create_order_fee_lines()  : mixed
Add fees to the order.
create_order_line_items()  : mixed
Add line items to the order.
create_order_shipping_lines()  : mixed
Add shipping lines to the order.
create_order_tax_lines()  : mixed
Add tax lines to the order.
get_checkout_fields()  : array
Get an array of checkout fields.
get_posted_address_data()  : string
Get a posted address field after sanitization and validation.
get_posted_data()  : array
Get posted data from the checkout form.
get_value()  : string
Gets the value either from POST, or from the customer object. Sets the default values in checkout fields.
instance()  : WC_Checkout
Gets the main WC_Checkout Instance.
is_registration_enabled()  : bool
Is registration enabled on the checkout page?
is_registration_required()  : bool
Is registration required to checkout?
process_checkout()  : mixed
Process the checkout after the confirm order button is pressed.
set_data_from_cart()  : mixed
Copy line items, tax, totals data from cart to order.
maybe_skip_fieldset()  : bool
See if a fieldset should be skipped.
process_customer()  : mixed
Create a new customer account if needed.
process_order_payment()  : mixed
Process an order that does require payment.
process_order_without_payment()  : mixed
Process an order that doesn't require payment.
send_ajax_failure_response()  : mixed
If checkout failed during an AJAX call, send failure response.
set_customer_address_fields()  : mixed
Set address field for customer.
update_session()  : mixed
Update customer and session data from the posted checkout data.
validate_checkout()  : mixed
Validates that the checkout has enough info to proceed.
validate_posted_data()  : mixed
Validates the posted checkout data based on field properties.

Properties

$legacy_posted_data

Holds posted data for backwards compatibility.

protected array $legacy_posted_data = array()

Methods

__get()

Gets the legacy public variables for backwards compatibility.

public __get(string $key) : array|string
Parameters
$key : string

Key.

Return values
array|string

__isset()

See if variable is set. Used to support legacy public variables which are no longer defined.

public __isset(string $key) : bool
Parameters
$key : string

Key.

Return values
bool

__set()

Sets the legacy public variables for backwards compatibility.

public __set(string $key, mixed $value) : mixed
Parameters
$key : string

Key.

$value : mixed

Value.

Return values
mixed

check_cart_items()

When we process the checkout, lets ensure cart items are rechecked to prevent checkout.

public check_cart_items() : mixed
Return values
mixed

create_order()

Create an order. Error codes: 520 - Cannot insert order into the database.

public create_order(array $data) : int|WP_ERROR

521 - Cannot get order after creation. 522 - Cannot update order. 525 - Cannot create line item. 526 - Cannot create fee item. 527 - Cannot create shipping item. 528 - Cannot create tax item. 529 - Cannot create coupon item.

Parameters
$data : array

Posted data.

Tags
throws
Exception

When checkout validation fails.

Return values
int|WP_ERROR

create_order_shipping_lines()

Add shipping lines to the order.

public create_order_shipping_lines(WC_Order &$order, array $chosen_shipping_methods, array $packages) : mixed
Parameters
$order : WC_Order

Order Instance.

$chosen_shipping_methods : array

Chosen shipping methods.

$packages : array

Packages.

Return values
mixed

get_checkout_fields()

Get an array of checkout fields.

public get_checkout_fields([string $fieldset = '' ]) : array
Parameters
$fieldset : string = ''

to get.

Return values
array

get_posted_address_data()

Get a posted address field after sanitization and validation.

public get_posted_address_data(string $key[, string $type = 'billing' ]) : string
Parameters
$key : string

Field key.

$type : string = 'billing'

Type of address. Available options: 'billing' or 'shipping'.

Return values
string

get_posted_data()

Get posted data from the checkout form.

public get_posted_data() : array
Tags
since
3.1.0
Return values
arrayof data.

get_value()

Gets the value either from POST, or from the customer object. Sets the default values in checkout fields.

public get_value(string $input) : string
Parameters
$input : string

Name of the input we want to grab data for. e.g. billing_country.

Return values
stringThe default value.

is_registration_enabled()

Is registration enabled on the checkout page?

public is_registration_enabled() : bool
Tags
since
3.0.0
Return values
bool

is_registration_required()

Is registration required to checkout?

public is_registration_required() : bool
Tags
since
3.0.0
Return values
bool

process_checkout()

Process the checkout after the confirm order button is pressed.

public process_checkout() : mixed
Tags
throws
Exception

When validation fails.

Return values
mixed

set_data_from_cart()

Copy line items, tax, totals data from cart to order.

public set_data_from_cart(WC_Order &$order) : mixed
Parameters
$order : WC_Order

Order object.

Tags
throws
Exception

When unable to create order.

Return values
mixed

maybe_skip_fieldset()

See if a fieldset should be skipped.

protected maybe_skip_fieldset(string $fieldset_key, array $data) : bool
Parameters
$fieldset_key : string

Fieldset key.

$data : array

Posted data.

Tags
since
3.0.0
Return values
bool

process_customer()

Create a new customer account if needed.

protected process_customer(array $data) : mixed
Parameters
$data : array

Posted data.

Tags
throws
Exception

When not able to create customer.

Return values
mixed

process_order_payment()

Process an order that does require payment.

protected process_order_payment(int $order_id, string $payment_method) : mixed
Parameters
$order_id : int

Order ID.

$payment_method : string

Payment method.

Tags
since
3.0.0
Return values
mixed

process_order_without_payment()

Process an order that doesn't require payment.

protected process_order_without_payment(int $order_id) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
3.0.0
Return values
mixed

send_ajax_failure_response()

If checkout failed during an AJAX call, send failure response.

protected send_ajax_failure_response() : mixed
Return values
mixed

set_customer_address_fields()

Set address field for customer.

protected set_customer_address_fields(string $field, string $key, array $data) : mixed
Parameters
$field : string

String to update.

$key : string

Field key.

$data : array

Array of data to get the value from.

Tags
since
3.0.7
Return values
mixed

update_session()

Update customer and session data from the posted checkout data.

protected update_session(array $data) : mixed
Parameters
$data : array

Posted data.

Tags
since
3.0.0
Return values
mixed

validate_checkout()

Validates that the checkout has enough info to proceed.

protected validate_checkout(array &$data, WP_Error &$errors) : mixed
Parameters
$data : array

An array of posted data.

$errors : WP_Error

Validation errors.

Tags
since
3.0.0
Return values
mixed

validate_posted_data()

Validates the posted checkout data based on field properties.

protected validate_posted_data(array &$data, WP_Error &$errors) : mixed
Parameters
$data : array

An array of posted data.

$errors : WP_Error

Validation error.

Tags
since
3.0.0
Return values
mixed