WooCommerce Code Reference

WC_Checkout
in package

Checkout class.

Table of Contents

$fields  : array<string|int, mixed>|null
Checkout fields are stored here.
$instance  : WC_Checkout|null
The single instance of the class.
$legacy_posted_data  : array<string|int, mixed>
Holds posted data for backwards compatibility.
$logged_in_customer  : WC_Customer
Caches customer object.
__clone()  : mixed
Cloning is forbidden.
__get()  : array<string|int, mixed>|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<string|int, mixed>
Get an array of checkout fields.
get_posted_address_data()  : string
Get a posted address field after sanitization and validation.
get_posted_data()  : array<string|int, mixed>
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<string|int, mixed> $legacy_posted_data = array()

Methods

__get()

Gets the legacy public variables for backwards compatibility.

public __get(string $key) : array<string|int, mixed>|string
Parameters
$key : string

Key.

Return values
array<string|int, mixed>|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

__wakeup()

Unserializing instances of this class is forbidden.

public __wakeup() : mixed
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

checkout_form_billing()

Output the billing form.

public checkout_form_billing() : mixed
Return values
mixed

checkout_form_shipping()

Output the shipping form.

public checkout_form_shipping() : mixed
Return values
mixed

create_order()

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

public create_order(array<string|int, mixed> $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<string|int, mixed>

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<string|int, mixed> $chosen_shipping_methods, array<string|int, mixed> $packages) : mixed
Parameters
$order : WC_Order

Order Instance.

$chosen_shipping_methods : array<string|int, mixed>

Chosen shipping methods.

$packages : array<string|int, mixed>

Packages.

Return values
mixed

get_checkout_fields()

Get an array of checkout fields.

public get_checkout_fields([string $fieldset = '' ]) : array<string|int, mixed>
Parameters
$fieldset : string = ''

to get.

Return values
array<string|int, mixed>

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; 'billing' or 'shipping'.

Return values
string

get_posted_data()

Get posted data from the checkout form.

public get_posted_data() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>of 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<string|int, mixed> $data) : bool
Parameters
$fieldset_key : string

Fieldset key.

$data : array<string|int, mixed>

Posted data.

Tags
since
3.0.0
Return values
bool

process_customer()

Create a new customer account if needed.

protected process_customer(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

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<string|int, mixed> $data) : mixed
Parameters
$field : string

String to update.

$key : string

Field key.

$data : array<string|int, mixed>

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<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

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<string|int, mixed> &$data, WP_Error &$errors) : mixed
Parameters
$data : array<string|int, mixed>

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<string|int, mixed> &$data, WP_Error &$errors) : mixed
Parameters
$data : array<string|int, mixed>

An array of posted data.

$errors : WP_Error

Validation error.

Tags
since
3.0.0
Return values
mixed