WooCommerce Code Reference

Search results

WC_Checkout

Checkout class.

Table of Contents

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

Properties

$fields

Checkout fields are stored here.

protected array|null $fields = \null

$legacy_posted_data

Holds posted data for backwards compatibility.

protected array $legacy_posted_data = array()

Methods

__isset()

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

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

Key.

Return values
bool

__set()

Sets the legacy public variables for backwards compatibility.

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

Key.

$value : mixed

Value.

Return values
mixed

__get()

Gets the legacy public variables for backwards compatibility.

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

Key.

Return values
array|string

__clone()

Cloning is forbidden.

public __clone( ) : mixed
Return values
mixed

__wakeup()

Unserializing instances of this class is forbidden.

public __wakeup( ) : mixed
Return values
mixed

is_registration_required()

Is registration required to checkout?

public is_registration_required( ) : bool
Tags
since
Return values
bool

is_registration_enabled()

Is registration enabled on the checkout page?

public is_registration_enabled( ) : bool
Tags
since
Return values
bool

get_checkout_fields()

Get an array of checkout fields.

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

to get.

Return values
array

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( $data : array ) : 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

When checkout validation fails.

Return values
int|WP_ERROR

set_data_from_cart()

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

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

Order object.

Tags
throws

When unable to create order.

Return values
mixed

create_order_line_items()

Add line items to the order.

public create_order_line_items( &$order : WC_Order , $cart : WC_Cart ) : mixed
Parameters
$order : WC_Order

Order instance.

$cart : WC_Cart

Cart instance.

Return values
mixed

create_order_shipping_lines()

Add shipping lines to the order.

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

Order Instance.

$chosen_shipping_methods : array

Chosen shipping methods.

$packages : array

Packages.

Return values
mixed

create_order_tax_lines()

Add tax lines to the order.

public create_order_tax_lines( &$order : WC_Order , $cart : WC_Cart ) : mixed
Parameters
$order : WC_Order

Order instance.

$cart : WC_Cart

Cart instance.

Return values
mixed

create_order_coupon_lines()

Add coupon lines to the order.

public create_order_coupon_lines( &$order : WC_Order , $cart : WC_Cart ) : mixed
Parameters
$order : WC_Order

Order instance.

$cart : WC_Cart

Cart instance.

Return values
mixed

maybe_skip_fieldset()

See if a fieldset should be skipped.

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

Fieldset key.

$data : array

Posted data.

Tags
since
Return values
bool

get_posted_data()

Get posted data from the checkout form.

public get_posted_data( ) : array
Tags
since
Return values
array

of data.

validate_posted_data()

Validates the posted checkout data based on field properties.

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

An array of posted data.

$errors : WP_Error

Validation error.

Tags
since
Return values
mixed

validate_checkout()

Validates that the checkout has enough info to proceed.

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

An array of posted data.

$errors : WP_Error

Validation errors.

Tags
since
Return values
mixed

set_customer_address_fields()

Set address field for customer.

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

String to update.

$key : string

Field key.

$data : array

Array of data to get the value from.

Tags
since
Return values
mixed

update_session()

Update customer and session data from the posted checkout data.

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

Posted data.

Tags
since
Return values
mixed

process_order_payment()

Process an order that does require payment.

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

Order ID.

$payment_method : string

Payment method.

Tags
since
Return values
mixed

process_order_without_payment()

Process an order that doesn't require payment.

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

Order ID.

Tags
since
Return values
mixed

process_customer()

Create a new customer account if needed.

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

Posted data.

Tags
throws

When not able to create customer.

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

process_checkout()

Process the checkout after the confirm order button is pressed.

public process_checkout( ) : mixed
Tags
throws

When validation fails.

Return values
mixed

get_posted_address_data()

Get a posted address field after sanitization and validation.

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

Field key.

$type : string = 'billing'

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

Return values
string

get_value()

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

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

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

Return values
string

The default value.

Back to the top