OrderController
in package
OrderController class.
Helper class which creates and syncs orders with the cart.
Table of Contents
- $additional_fields_controller : CheckoutFields
- Checkout fields controller.
- __construct() : mixed
- Constructor.
- create_order_from_cart() : WC_Order
- Create order and set props based on global settings.
- default_order_status() : string
- Changes default order status to draft for orders created via this API.
- get_failed_order_stock_error() : mixed
- Get errors for order stock on failed orders.
- sync_customer_data_with_order() : mixed
- Copies order data to customer object (not the session), so values persist for future checkouts.
- update_order_from_cart() : mixed
- Update an order using data from the current cart.
- validate_order_before_payment() : mixed
- Final validation ran before payment is taken.
- validate_order_key() : mixed
- Validate a given order key against an existing order.
- validate_selected_shipping_methods() : mixed
- Check there is a shipping method if it requires shipping.
- get_coupon() : WC_Coupon
- Convert a coupon code to a coupon object.
- update_addresses_from_cart() : mixed
- Update address data from cart and/or customer session data.
- update_line_items_from_cart() : mixed
- Create order line items.
- validate_address_fields() : mixed
- Check all required address fields are set and return errors if not.
- validate_addresses() : mixed
- Validates customer address data based on the locale to ensure required fields are set.
- validate_allowed_country() : bool
- Check all required address fields are set and return errors if not.
- validate_coupon_email_restriction() : mixed
- Check email restrictions of a coupon against the order.
- validate_coupon_usage_limit() : mixed
- Check usage restrictions of a coupon against the order.
- validate_coupons() : mixed
- Validate coupons applied to the order and remove those that are not valid.
- validate_email() : mixed
- Validates the customer email. This is a required field.
- get_email_from_user_id() : string
- Get user email from user id.
- get_usage_per_aliases() : int
- Get the usage count for a coupon based on a list of aliases (ids, emails).
Properties
$additional_fields_controller
Checkout fields controller.
private
CheckoutFields
$additional_fields_controller
Methods
__construct()
Constructor.
public
__construct() : mixed
Return values
mixed —create_order_from_cart()
Create order and set props based on global settings.
public
create_order_from_cart() : WC_Order
Tags
Return values
WC_Order — A new order object.default_order_status()
Changes default order status to draft for orders created via this API.
public
default_order_status() : string
Return values
string —get_failed_order_stock_error()
Get errors for order stock on failed orders.
public
get_failed_order_stock_error(int $order_id) : mixed
Parameters
- $order_id : int
-
Order ID.
Tags
Return values
mixed —sync_customer_data_with_order()
Copies order data to customer object (not the session), so values persist for future checkouts.
public
sync_customer_data_with_order(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Return values
mixed —update_order_from_cart()
Update an order using data from the current cart.
public
update_order_from_cart(WC_Order $order[, bool $update_totals = true ]) : mixed
Parameters
- $order : WC_Order
-
The order object to update.
- $update_totals : bool = true
-
Whether to update totals or not.
Return values
mixed —validate_order_before_payment()
Final validation ran before payment is taken.
public
validate_order_before_payment(WC_Order $order) : mixed
By this point we have an order populated with customer data and items.
Parameters
- $order : WC_Order
-
Order object.
Tags
Return values
mixed —validate_order_key()
Validate a given order key against an existing order.
public
validate_order_key(int $order_id, string $order_key) : mixed
Parameters
- $order_id : int
-
Order ID.
- $order_key : string
-
Order key.
Tags
Return values
mixed —validate_selected_shipping_methods()
Check there is a shipping method if it requires shipping.
public
validate_selected_shipping_methods(bool $needs_shipping[, array<string|int, mixed> $chosen_shipping_methods = array() ]) : mixed
Parameters
- $needs_shipping : bool
-
Current order needs shipping.
- $chosen_shipping_methods : array<string|int, mixed> = array()
-
Array of shipping methods.
Tags
Return values
mixed —get_coupon()
Convert a coupon code to a coupon object.
protected
get_coupon(string $coupon_code) : WC_Coupon
Parameters
- $coupon_code : string
-
Coupon code.
Return values
WC_Coupon — Coupon object.update_addresses_from_cart()
Update address data from cart and/or customer session data.
protected
update_addresses_from_cart(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
The order object to update.
Return values
mixed —update_line_items_from_cart()
Create order line items.
protected
update_line_items_from_cart(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
The order object to update.
Return values
mixed —validate_address_fields()
Check all required address fields are set and return errors if not.
protected
validate_address_fields(WC_Order $order, string $address_type, WP_Error $errors) : mixed
Parameters
- $order : WC_Order
-
Order object.
- $address_type : string
-
billing or shipping address, used in error messages.
- $errors : WP_Error
-
Error object.
Return values
mixed —validate_addresses()
Validates customer address data based on the locale to ensure required fields are set.
protected
validate_addresses(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Tags
Return values
mixed —validate_allowed_country()
Check all required address fields are set and return errors if not.
protected
validate_allowed_country(string $country, array<string|int, mixed> $allowed_countries) : bool
Parameters
- $country : string
-
Country code.
- $allowed_countries : array<string|int, mixed>
-
List of valid country codes.
Return values
bool — True if valid.validate_coupon_email_restriction()
Check email restrictions of a coupon against the order.
protected
validate_coupon_email_restriction(WC_Coupon $coupon, WC_Order $order) : mixed
Parameters
Tags
Return values
mixed —validate_coupon_usage_limit()
Check usage restrictions of a coupon against the order.
protected
validate_coupon_usage_limit(WC_Coupon $coupon, WC_Order $order) : mixed
Parameters
Tags
Return values
mixed —validate_coupons()
Validate coupons applied to the order and remove those that are not valid.
protected
validate_coupons(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Tags
Return values
mixed —validate_email()
Validates the customer email. This is a required field.
protected
validate_email(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Tags
Return values
mixed —get_email_from_user_id()
Get user email from user id.
private
get_email_from_user_id(int $user_id) : string
Parameters
- $user_id : int
-
User ID.
Return values
string — Email or empty string.get_usage_per_aliases()
Get the usage count for a coupon based on a list of aliases (ids, emails).
private
get_usage_per_aliases(WC_Coupon $coupon, array<string|int, mixed> $aliases) : int
Parameters
- $coupon : WC_Coupon
-
Coupon object applied to the cart.
- $aliases : array<string|int, mixed>
-
List of aliases to check.