PHP Class WC_Order

Author: WooThemes
Inheritance: extends WC_Abstract_Order
显示文件 Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$data array Order Data array. This is the core order data exposed in APIs since 2.7.0.
$status_transition boolean | array Stores data about status changes so relevant hooks can be fired.

Public Methods

Method Description
add_order_note ( string $note, integer $is_customer_note, $added_by_user = false ) : integer Adds a note (comment) to the order. Order must exist.
get_address ( string $type = 'billing' ) : array Returns the requested address in raw, non-formatted way.
get_billing_address_1 ( string $context = 'view' ) : string Get billing_address_1.
get_billing_address_2 ( string $context = 'view' ) : string Get billing_address_2.
get_billing_city ( string $context = 'view' ) : string Get billing_city.
get_billing_company ( string $context = 'view' ) : string Get billing_company.
get_billing_country ( string $context = 'view' ) : string Get billing_country.
get_billing_email ( string $context = 'view' ) : string Get billing_email.
get_billing_first_name ( string $context = 'view' ) : string Get billing_first_name.
get_billing_last_name ( string $context = 'view' ) : string Get billing_last_name.
get_billing_phone ( string $context = 'view' ) : string Get billing_phone.
get_billing_postcode ( string $context = 'view' ) : string Get billing_postcode.
get_billing_state ( string $context = 'view' ) : string Get billing_state.
get_cancel_endpoint ( ) : string Helper method to return the cancel endpoint.
get_cancel_order_url ( string $redirect = '' ) : string Generates a URL so that a customer can cancel their (unpaid - pending) order.
get_cancel_order_url_raw ( string $redirect = '' ) : string Generates a raw (unescaped) cancel-order URL for use by payment gateways.
get_cart_hash ( string $context = 'view' ) : string Get cart hash.
get_checkout_order_received_url ( ) : string Generates a URL for the thanks page (order received).
get_checkout_payment_url ( boolean $on_checkout = false ) : string Generates a URL so that a customer can pay for their (unpaid - pending) order. Pass 'true' for the checkout version which doesn't offer gateway choices.
get_created_via ( string $context = 'view' ) : string Get created_via.
get_customer_id ( string $context = 'view' ) : integer Get customer_id.
get_customer_ip_address ( string $context = 'view' ) : string Get customer_ip_address.
get_customer_note ( string $context = 'view' ) : string Get customer_note.
get_customer_order_notes ( ) : array List order notes (public) for the customer.
get_customer_user_agent ( string $context = 'view' ) : string Get customer_user_agent.
get_data ( ) : array Get all class data in array format.
get_date_completed ( string $context = 'view' ) : integer Get date_completed.
get_date_paid ( string $context = 'view' ) : integer Get date_paid.
get_formatted_billing_address ( ) : string Get a formatted billing address for the order.
get_formatted_billing_full_name ( ) : string Get a formatted billing full name.
get_formatted_order_total ( string $tax_display = '', boolean $display_refunded = true ) : string Gets order total - formatted for display.
get_formatted_shipping_address ( ) : string Get a formatted shipping address for the order.
get_formatted_shipping_full_name ( ) : string Get a formatted shipping full name.
get_item_count_refunded ( string $item_type = '' ) : string Gets the count of order items of a certain type that have been refunded.
get_order_key ( string $context = 'view' ) : string Get order key.
get_order_number ( ) : string get_order_number function.
get_payment_method ( string $context = 'view' ) : string Get the payment method.
get_payment_method_title ( string $context = 'view' ) : string Get payment_method_title.
get_qty_refunded_for_item ( integer $item_id, string $item_type = 'line_item' ) : integer Get the refunded amount for a line item.
get_refunds ( ) : array Get order refunds.
get_remaining_refund_amount ( ) : string How much money is left to refund?
get_remaining_refund_items ( ) : integer How many items are left to refund?
get_shipping_address_1 ( string $context = 'view' ) : string Get shipping_address_1.
get_shipping_address_2 ( string $context = 'view' ) : string Get shipping_address_2.
get_shipping_address_map_url ( ) : string Get a formatted shipping address for the order.
get_shipping_city ( string $context = 'view' ) : string Get shipping_city.
get_shipping_company ( string $context = 'view' ) : string Get shipping_company.
get_shipping_country ( string $context = 'view' ) : string Get shipping_country.
get_shipping_first_name ( string $context = 'view' ) : string Get shipping_first_name.
get_shipping_last_name ( string $context = 'view' ) : string Get shipping_last_name.
get_shipping_postcode ( string $context = 'view' ) : string Get shipping_postcode.
get_shipping_state ( string $context = 'view' ) : string Get shipping_state.
get_tax_refunded_for_item ( integer $item_id, integer $tax_id, string $item_type = 'line_item' ) : double Get the refunded amount for a line item.
get_total_qty_refunded ( string $item_type = 'line_item' ) : integer Get the total number of items refunded.
get_total_refunded ( ) : string Get amount already refunded.
get_total_refunded_for_item ( integer $item_id, string $item_type = 'line_item' ) : integer Get the refunded amount for a line item.
get_total_shipping_refunded ( ) : float Get the total shipping refunded.
get_total_tax_refunded ( ) : float Get the total tax refunded.
get_total_tax_refunded_by_rate_id ( integer $rate_id ) : float Get total tax refunded by rate ID.
get_transaction_id ( string $context = 'view' ) : string Get transaction_id.
get_user ( ) : WP_User | false Get the user associated with the order. False for guests.
get_user_id ( string $context = 'view' ) : integer Alias for get_customer_id().
get_view_order_url ( ) : string Generates a URL to view an order from the my account page.
has_cart_hash ( $cart_hash = '' ) : boolean See if order matches cart_hash.
has_downloadable_item ( ) : boolean Returns true if the order contains a downloadable product.
is_download_permitted ( ) : boolean Checks if product download is permitted.
is_editable ( ) : boolean Checks if an order can be edited, specifically for use on the Edit Order screen.
is_paid ( ) : boolean Returns if an order has been paid for based on the order status.
key_is_valid ( mixed $key ) : boolean Check if an order key is valid.
needs_payment ( ) : boolean Checks if an order needs payment, based on status and order total.
needs_shipping_address ( ) : boolean Checks if an order needs display the shipping address, based on shipping method.
payment_complete ( string $transaction_id = '' ) : boolean When a payment is complete this function is called.
save ( ) : integer Save data to the database.
set_billing_address_1 ( string $value ) Set billing_address_1.
set_billing_address_2 ( string $value ) Set billing_address_2.
set_billing_city ( string $value ) Set billing_city.
set_billing_company ( string $value ) Set billing_company.
set_billing_country ( string $value ) Set billing_country.
set_billing_email ( string $value ) Set billing_email.
set_billing_first_name ( string $value ) Set billing_first_name.
set_billing_last_name ( string $value ) Set billing_last_name.
set_billing_phone ( string $value ) Set billing_phone.
set_billing_postcode ( string $value ) Set billing_postcode.
set_billing_state ( string $value ) Set billing_state.
set_cart_hash ( string $value ) Set cart hash.
set_created_via ( string $value ) Set created_via.
set_customer_id ( integer $value ) Set customer_id.
set_customer_ip_address ( string $value ) Set customer_ip_address.
set_customer_note ( string $value ) Set customer_note.
set_customer_user_agent ( string $value ) Set customer_user_agent.
set_date_completed ( string $timestamp ) Set date_completed.
set_date_paid ( string $timestamp ) Set date_paid.
set_order_key ( string $value ) Set order_key.
set_payment_method ( string $payment_method = '' ) Set the payment method.
set_payment_method_title ( string $value ) Set payment_method_title.
set_shipping_address_1 ( string $value ) Set shipping_address_1.
set_shipping_address_2 ( string $value ) Set shipping_address_2.
set_shipping_city ( string $value ) Set shipping_city.
set_shipping_company ( string $value ) Set shipping_company.
set_shipping_country ( string $value ) Set shipping_country.
set_shipping_first_name ( string $value ) Set shipping_first_name.
set_shipping_last_name ( string $value ) Set shipping_last_name.
set_shipping_postcode ( string $value ) Set shipping_postcode.
set_shipping_state ( string $value ) Set shipping_state.
set_status ( string $new_status, string $note = '', boolean $manual_update = false ) Set order status.
set_transaction_id ( string $value ) Set transaction_id.
update_status ( $new_status, $note = '', $manual = false ) : boolean Updates status of order immediately. Order must exist.

Protected Methods

Method Description
get_address_prop ( string $prop, string $address = 'billing', string $context = 'view' ) : mixed Gets a prop for a getter method.
maybe_set_user_billing_email ( ) Maybe set empty billing email to that of the user who owns the order.
set_address_prop ( string $prop, string $address = 'billing', mixed $value ) Sets a prop for a setter method.
status_transition ( ) Handle the status transition.

Method Details

add_order_note() public method

Adds a note (comment) to the order. Order must exist.
public add_order_note ( string $note, integer $is_customer_note, $added_by_user = false ) : integer
$note string Note to add.
$is_customer_note integer (default: 0) Is this a note for the customer?
return integer Comment ID.

get_address() public method

Note: Merges raw data with get_prop data so changes are returned too.
Since: 2.4.0
public get_address ( string $type = 'billing' ) : array
$type string Billing or shipping. Anything else besides 'billing' will return shipping address.
return array The stored address after filter.

get_address_prop() protected method

Gets a prop for a getter method.
Since: 2.7.0
protected get_address_prop ( string $prop, string $address = 'billing', string $context = 'view' ) : mixed
$prop string Name of prop to get.
$address string billing or shipping.
$context string What the value is for. Valid values are view and edit.
return mixed

get_billing_address_1() public method

Get billing_address_1.
public get_billing_address_1 ( string $context = 'view' ) : string
$context string
return string

get_billing_address_2() public method

Get billing_address_2.
public get_billing_address_2 ( string $context = 'view' ) : string
$context string
return string $value

get_billing_city() public method

Get billing_city.
public get_billing_city ( string $context = 'view' ) : string
$context string
return string $value

get_billing_company() public method

Get billing_company.
public get_billing_company ( string $context = 'view' ) : string
$context string
return string

get_billing_country() public method

Get billing_country.
public get_billing_country ( string $context = 'view' ) : string
$context string
return string

get_billing_email() public method

Get billing_email.
public get_billing_email ( string $context = 'view' ) : string
$context string
return string

get_billing_first_name() public method

Get billing_first_name.
public get_billing_first_name ( string $context = 'view' ) : string
$context string
return string

get_billing_last_name() public method

Get billing_last_name.
public get_billing_last_name ( string $context = 'view' ) : string
$context string
return string

get_billing_phone() public method

Get billing_phone.
public get_billing_phone ( string $context = 'view' ) : string
$context string
return string

get_billing_postcode() public method

Get billing_postcode.
public get_billing_postcode ( string $context = 'view' ) : string
$context string
return string

get_billing_state() public method

Get billing_state.
public get_billing_state ( string $context = 'view' ) : string
$context string
return string

get_cancel_endpoint() public method

Helper method to return the cancel endpoint.
public get_cancel_endpoint ( ) : string
return string the cancel endpoint; either the cart page or the home page.

get_cancel_order_url() public method

Generates a URL so that a customer can cancel their (unpaid - pending) order.
public get_cancel_order_url ( string $redirect = '' ) : string
$redirect string
return string

get_cancel_order_url_raw() public method

Generates a raw (unescaped) cancel-order URL for use by payment gateways.
public get_cancel_order_url_raw ( string $redirect = '' ) : string
$redirect string
return string The unescaped cancel-order URL.

get_cart_hash() public method

Get cart hash.
public get_cart_hash ( string $context = 'view' ) : string
$context string
return string

get_checkout_order_received_url() public method

Generates a URL for the thanks page (order received).

get_checkout_payment_url() public method

Generates a URL so that a customer can pay for their (unpaid - pending) order. Pass 'true' for the checkout version which doesn't offer gateway choices.
public get_checkout_payment_url ( boolean $on_checkout = false ) : string
$on_checkout boolean
return string

get_created_via() public method

Get created_via.
public get_created_via ( string $context = 'view' ) : string
$context string
return string

get_customer_id() public method

Get customer_id.
public get_customer_id ( string $context = 'view' ) : integer
$context string
return integer

get_customer_ip_address() public method

Get customer_ip_address.
public get_customer_ip_address ( string $context = 'view' ) : string
$context string
return string

get_customer_note() public method

Get customer_note.
public get_customer_note ( string $context = 'view' ) : string
$context string
return string

get_customer_order_notes() public method

List order notes (public) for the customer.
public get_customer_order_notes ( ) : array
return array

get_customer_user_agent() public method

Get customer_user_agent.
public get_customer_user_agent ( string $context = 'view' ) : string
$context string
return string

get_data() public method

Get all class data in array format.
Since: 2.7.0
public get_data ( ) : array
return array

get_date_completed() public method

Get date_completed.
public get_date_completed ( string $context = 'view' ) : integer
$context string
return integer

get_date_paid() public method

Get date_paid.
public get_date_paid ( string $context = 'view' ) : integer
$context string
return integer

get_formatted_billing_address() public method

Get a formatted billing address for the order.

get_formatted_billing_full_name() public method

Get a formatted billing full name.

get_formatted_order_total() public method

Gets order total - formatted for display.
public get_formatted_order_total ( string $tax_display = '', boolean $display_refunded = true ) : string
$tax_display string Type of tax display.
$display_refunded boolean If should include refunded value.
return string

get_formatted_shipping_address() public method

Get a formatted shipping address for the order.

get_formatted_shipping_full_name() public method

Get a formatted shipping full name.

get_item_count_refunded() public method

Gets the count of order items of a certain type that have been refunded.
Since: 2.4.0
public get_item_count_refunded ( string $item_type = '' ) : string
$item_type string
return string

get_order_key() public method

Get order key.
Since: 2.7.0
public get_order_key ( string $context = 'view' ) : string
$context string
return string

get_order_number() public method

Gets the order number for display (by default, order ID).
public get_order_number ( ) : string
return string

get_payment_method() public method

Get the payment method.
public get_payment_method ( string $context = 'view' ) : string
$context string
return string

get_payment_method_title() public method

Get payment_method_title.
public get_payment_method_title ( string $context = 'view' ) : string
$context string
return string

get_qty_refunded_for_item() public method

Get the refunded amount for a line item.
public get_qty_refunded_for_item ( integer $item_id, string $item_type = 'line_item' ) : integer
$item_id integer ID of the item we're checking
$item_type string type of the item we're checking, if not a line_item
return integer

get_refunds() public method

Get order refunds.
Since: 2.2
public get_refunds ( ) : array
return array of WC_Order_Refund objects

get_remaining_refund_amount() public method

How much money is left to refund?

get_remaining_refund_items() public method

How many items are left to refund?

get_shipping_address_1() public method

Get shipping_address_1.
public get_shipping_address_1 ( string $context = 'view' ) : string
$context string
return string

get_shipping_address_2() public method

Get shipping_address_2.
public get_shipping_address_2 ( string $context = 'view' ) : string
$context string
return string

get_shipping_address_map_url() public method

Get a formatted shipping address for the order.

get_shipping_city() public method

Get shipping_city.
public get_shipping_city ( string $context = 'view' ) : string
$context string
return string

get_shipping_company() public method

Get shipping_company.
public get_shipping_company ( string $context = 'view' ) : string
$context string
return string

get_shipping_country() public method

Get shipping_country.
public get_shipping_country ( string $context = 'view' ) : string
$context string
return string

get_shipping_first_name() public method

Get shipping_first_name.
public get_shipping_first_name ( string $context = 'view' ) : string
$context string
return string

get_shipping_last_name() public method

Get shipping_last_name.
public get_shipping_last_name ( string $context = 'view' ) : string
$context string
return string

get_shipping_postcode() public method

Get shipping_postcode.
public get_shipping_postcode ( string $context = 'view' ) : string
$context string
return string

get_shipping_state() public method

Get shipping_state.
public get_shipping_state ( string $context = 'view' ) : string
$context string
return string

get_tax_refunded_for_item() public method

Get the refunded amount for a line item.
public get_tax_refunded_for_item ( integer $item_id, integer $tax_id, string $item_type = 'line_item' ) : double
$item_id integer ID of the item we're checking
$tax_id integer ID of the tax we're checking
$item_type string type of the item we're checking, if not a line_item
return double

get_total_qty_refunded() public method

Get the total number of items refunded.
Since: 2.4.0
public get_total_qty_refunded ( string $item_type = 'line_item' ) : integer
$item_type string type of the item we're checking, if not a line_item
return integer

get_total_refunded() public method

Get amount already refunded.
Since: 2.2
public get_total_refunded ( ) : string
return string

get_total_refunded_for_item() public method

Get the refunded amount for a line item.
public get_total_refunded_for_item ( integer $item_id, string $item_type = 'line_item' ) : integer
$item_id integer ID of the item we're checking
$item_type string type of the item we're checking, if not a line_item
return integer

get_total_shipping_refunded() public method

Get the total shipping refunded.
Since: 2.4

get_total_tax_refunded() public method

Get the total tax refunded.
Since: 2.3
public get_total_tax_refunded ( ) : float
return float

get_total_tax_refunded_by_rate_id() public method

Get total tax refunded by rate ID.
public get_total_tax_refunded_by_rate_id ( integer $rate_id ) : float
$rate_id integer
return float

get_transaction_id() public method

Get transaction_id.
public get_transaction_id ( string $context = 'view' ) : string
$context string
return string

get_user() public method

Get the user associated with the order. False for guests.
public get_user ( ) : WP_User | false
return WP_User | false

get_user_id() public method

Alias for get_customer_id().
public get_user_id ( string $context = 'view' ) : integer
$context string
return integer

get_view_order_url() public method

Generates a URL to view an order from the my account page.
public get_view_order_url ( ) : string
return string

has_cart_hash() public method

See if order matches cart_hash.
public has_cart_hash ( $cart_hash = '' ) : boolean
return boolean

has_downloadable_item() public method

Returns true if the order contains a downloadable product.
public has_downloadable_item ( ) : boolean
return boolean

is_download_permitted() public method

Checks if product download is permitted.
public is_download_permitted ( ) : boolean
return boolean

is_editable() public method

Checks if an order can be edited, specifically for use on the Edit Order screen.
public is_editable ( ) : boolean
return boolean

is_paid() public method

Returns if an order has been paid for based on the order status.
Since: 2.5.0
public is_paid ( ) : boolean
return boolean

key_is_valid() public method

Check if an order key is valid.
public key_is_valid ( mixed $key ) : boolean
$key mixed
return boolean

maybe_set_user_billing_email() protected method

Maybe set empty billing email to that of the user who owns the order.

needs_payment() public method

Checks if an order needs payment, based on status and order total.
public needs_payment ( ) : boolean
return boolean

needs_shipping_address() public method

Checks if an order needs display the shipping address, based on shipping method.
public needs_shipping_address ( ) : boolean
return boolean

payment_complete() public method

Most of the time this should mark an order as 'processing' so that admin can process/post the items. If the cart contains only downloadable items then the order is 'completed' since the admin needs to take no action. Stock levels are reduced at this point. Sales are also recorded for products. Finally, record the date of payment. Order must exist.
public payment_complete ( string $transaction_id = '' ) : boolean
$transaction_id string Optional transaction id to store in post meta.
return boolean success

save() public method

Save data to the database.
Since: 2.7.0
public save ( ) : integer
return integer order ID

set_address_prop() protected method

Sets a prop for a setter method.
Since: 2.7.0
protected set_address_prop ( string $prop, string $address = 'billing', mixed $value )
$prop string Name of prop to set.
$address string Name of address to set. billing or shipping.
$value mixed Value of the prop.

set_billing_address_1() public method

Set billing_address_1.
public set_billing_address_1 ( string $value )
$value string

set_billing_address_2() public method

Set billing_address_2.
public set_billing_address_2 ( string $value )
$value string

set_billing_city() public method

Set billing_city.
public set_billing_city ( string $value )
$value string

set_billing_company() public method

Set billing_company.
public set_billing_company ( string $value )
$value string

set_billing_country() public method

Set billing_country.
public set_billing_country ( string $value )
$value string

set_billing_email() public method

Set billing_email.
public set_billing_email ( string $value )
$value string

set_billing_first_name() public method

Set billing_first_name.
public set_billing_first_name ( string $value )
$value string

set_billing_last_name() public method

Set billing_last_name.
public set_billing_last_name ( string $value )
$value string

set_billing_phone() public method

Set billing_phone.
public set_billing_phone ( string $value )
$value string

set_billing_postcode() public method

Set billing_postcode.
public set_billing_postcode ( string $value )
$value string

set_billing_state() public method

Set billing_state.
public set_billing_state ( string $value )
$value string

set_cart_hash() public method

Set cart hash.
public set_cart_hash ( string $value )
$value string

set_created_via() public method

Set created_via.
public set_created_via ( string $value )
$value string

set_customer_id() public method

Set customer_id.
public set_customer_id ( integer $value )
$value integer

set_customer_ip_address() public method

Set customer_ip_address.
public set_customer_ip_address ( string $value )
$value string

set_customer_note() public method

Set customer_note.
public set_customer_note ( string $value )
$value string

set_customer_user_agent() public method

Set customer_user_agent.
public set_customer_user_agent ( string $value )
$value string

set_date_completed() public method

Set date_completed.
public set_date_completed ( string $timestamp )
$timestamp string

set_date_paid() public method

Set date_paid.
public set_date_paid ( string $timestamp )
$timestamp string

set_order_key() public method

Set order_key.
public set_order_key ( string $value )
$value string Max length 20 chars.

set_payment_method() public method

Set the payment method.
public set_payment_method ( string $payment_method = '' )
$payment_method string Supports WC_Payment_Gateway for bw compatibility with < 2.7

set_payment_method_title() public method

Set payment_method_title.
public set_payment_method_title ( string $value )
$value string

set_shipping_address_1() public method

Set shipping_address_1.
public set_shipping_address_1 ( string $value )
$value string

set_shipping_address_2() public method

Set shipping_address_2.
public set_shipping_address_2 ( string $value )
$value string

set_shipping_city() public method

Set shipping_city.
public set_shipping_city ( string $value )
$value string

set_shipping_company() public method

Set shipping_company.
public set_shipping_company ( string $value )
$value string

set_shipping_country() public method

Set shipping_country.
public set_shipping_country ( string $value )
$value string

set_shipping_first_name() public method

Set shipping_first_name.
public set_shipping_first_name ( string $value )
$value string

set_shipping_last_name() public method

Set shipping_last_name.
public set_shipping_last_name ( string $value )
$value string

set_shipping_postcode() public method

Set shipping_postcode.
public set_shipping_postcode ( string $value )
$value string

set_shipping_state() public method

Set shipping_state.
public set_shipping_state ( string $value )
$value string

set_status() public method

Set order status.
Since: 2.7.0
public set_status ( string $new_status, string $note = '', boolean $manual_update = false )
$new_status string Status to change the order to. No internal wc- prefix is required.
$note string (default: '') Optional note to add.
$manual_update boolean is this a manual order status change?

set_transaction_id() public method

Set transaction_id.
public set_transaction_id ( string $value )
$value string

status_transition() protected method

Handle the status transition.
protected status_transition ( )

update_status() public method

Updates status of order immediately. Order must exist.
public update_status ( $new_status, $note = '', $manual = false ) : boolean
return boolean success

Property Details

$data protected_oe property

Order Data array. This is the core order data exposed in APIs since 2.7.0.
Since: 2.7.0
protected array $data
return array

$status_transition protected_oe property

Stores data about status changes so relevant hooks can be fired.
protected bool|array $status_transition
return boolean | array