PHP Class WC_Checkout

The WooCommerce checkout class handles the checkout process, collecting user data and processing the payment.
Author: WooThemes
Mostrar archivo Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$fields array | null Checkout fields are stored here.
$instance WC_Checkout | null The single instance of the class.

Public Methods

Method Description
__clone ( ) Cloning is forbidden.
__get ( string $key ) : string Gets the legacy public variables for backwards compatibility.
__isset ( string $key ) : boolean See if variable is set. Used to support legacy public variables which are no longer defined.
__set ( string $key, mixed $value ) Sets the legacy public variables for backwards compatibility.
__wakeup ( ) Unserializing instances of this class is forbidden.
check_cart_items ( ) When we process the checkout, lets ensure cart items are rechecked to prevent checkout.
checkout_form_billing ( ) Output the billing form.
checkout_form_shipping ( ) Output the shipping form.
create_order ( $data ) : integer | WP_ERROR Create an order. Error codes: 520 - Cannot insert order into the database.
get_checkout_fields ( string $fieldset = '' ) : array Get an array of checkout fields.
get_posted_address_data ( string $key, string $type = 'billing' ) : string Get a posted address field after sanitization and validation.
get_value ( string $input ) : string | null Gets the value either from the posted data, or from the users meta data.
instance ( ) : WC_Checkout Gets the main WC_Checkout Instance.
is_registration_enabled ( ) : boolean Is registration enabled on the checkout page?
is_registration_required ( ) : boolean Is registration required to checkout?
process_checkout ( ) Process the checkout after the confirm order button is pressed.

Protected Methods

Method Description
create_order_coupon_lines ( WC_Order &$order ) Add coupon lines to the order.
create_order_fee_lines ( WC_Order &$order ) Add fees to the order.
create_order_line_items ( WC_Order &$order ) Add line items to the order.
create_order_shipping_lines ( WC_Order &$order ) Add shipping lines to the order.
create_order_tax_lines ( WC_Order &$order ) Add tax lines to the order.
get_posted_data ( ) : array Get posted data from the checkout form.
maybe_skip_fieldset ( string $fieldset_key, array $data ) See if a fieldset should be skipped.
process_customer ( array $data ) Create a new customer account if needed.
process_order_payment ( integer $order_id, string $payment_method ) Process an order that does require payment.
process_order_without_payment ( integer $order_id ) Process an order that doesn't require payment.
send_ajax_failure_response ( ) If checkout failed during an AJAX call, send failure response.
update_session ( array $data ) Update customer and session data from the posted checkout data.
validate_checkout ( array &$data, WP_Error &$errors ) Validates that the checkout has enough info to proceed.
validate_posted_data ( array &$data, WP_Error &$errors ) Validates the posted checkout data based on field properties.

Method Details

__clone() public method

Cloning is forbidden.
public __clone ( )

__get() public method

Gets the legacy public variables for backwards compatibility.
public __get ( string $key ) : string
$key string
return string

__isset() public method

See if variable is set. Used to support legacy public variables which are no longer defined.
public __isset ( string $key ) : boolean
$key string
return boolean

__set() public method

Sets the legacy public variables for backwards compatibility.
public __set ( string $key, mixed $value )
$key string
$value mixed

__wakeup() public method

Unserializing instances of this class is forbidden.
public __wakeup ( )

check_cart_items() public method

When we process the checkout, lets ensure cart items are rechecked to prevent checkout.
public check_cart_items ( )

checkout_form_billing() public method

Output the billing form.

checkout_form_shipping() public method

Output the shipping form.

create_order() public method

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.
public create_order ( $data ) : integer | WP_ERROR
$data Posted data.
return integer | WP_ERROR

create_order_coupon_lines() protected method

Add coupon lines to the order.
protected create_order_coupon_lines ( WC_Order &$order )
$order WC_Order

create_order_fee_lines() protected method

Add fees to the order.
protected create_order_fee_lines ( WC_Order &$order )
$order WC_Order

create_order_line_items() protected method

Add line items to the order.
protected create_order_line_items ( WC_Order &$order )
$order WC_Order

create_order_shipping_lines() protected method

Add shipping lines to the order.
protected create_order_shipping_lines ( WC_Order &$order )
$order WC_Order

create_order_tax_lines() protected method

Add tax lines to the order.
protected create_order_tax_lines ( WC_Order &$order )
$order WC_Order

get_checkout_fields() public method

Get an array of checkout fields.
public get_checkout_fields ( string $fieldset = '' ) : array
$fieldset string to get.
return array

get_posted_address_data() public method

Get a posted address field after sanitization and validation.
public get_posted_address_data ( string $key, string $type = 'billing' ) : string
$key string
$type string billing for shipping
return string

get_posted_data() protected method

Get posted data from the checkout form.
Since: 2.7.0
protected get_posted_data ( ) : array
return array of data and errors.

get_value() public method

Gets the value either from the posted data, or from the users meta data.
public get_value ( string $input ) : string | null
$input string
return string | null

instance() public static method

Gets the main WC_Checkout Instance.
Since: 2.1
public static instance ( ) : WC_Checkout
return WC_Checkout Main instance

is_registration_enabled() public method

Is registration enabled on the checkout page?
Since: 2.7.0

is_registration_required() public method

Is registration required to checkout?
Since: 2.7.0

maybe_skip_fieldset() protected method

See if a fieldset should be skipped.
Since: 2.7.0
protected maybe_skip_fieldset ( string $fieldset_key, array $data )
$fieldset_key string
$data array

process_checkout() public method

Process the checkout after the confirm order button is pressed.
public process_checkout ( )

process_customer() protected method

Create a new customer account if needed.
protected process_customer ( array $data )
$data array

process_order_payment() protected method

Process an order that does require payment.
Since: 2.7.0
protected process_order_payment ( integer $order_id, string $payment_method )
$order_id integer
$payment_method string

process_order_without_payment() protected method

Process an order that doesn't require payment.
Since: 2.7.0
protected process_order_without_payment ( integer $order_id )
$order_id integer

send_ajax_failure_response() protected method

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

update_session() protected method

Update customer and session data from the posted checkout data.
Since: 2.7.0
protected update_session ( array $data )
$data array

validate_checkout() protected method

Validates that the checkout has enough info to proceed.
Since: 2.7.0
protected validate_checkout ( array &$data, WP_Error &$errors )
$data array An array of posted data.
$errors WP_Error

validate_posted_data() protected method

Validates the posted checkout data based on field properties.
Since: 2.7.0
protected validate_posted_data ( array &$data, WP_Error &$errors )
$data array An array of posted data.
$errors WP_Error

Property Details

$fields protected_oe property

Checkout fields are stored here.
protected array|null $fields
return array | null

$instance protected_oe static_oe property

The single instance of the class.
protected static WC_Checkout|null $instance
return WC_Checkout | null