PHP Class WC_Abstract_Order

The WooCommerce order class handles order data.
Author: WooThemes
Afficher le fichier Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Свойство Type Description
$cache_group string A group must be set to to enable caching.
$data array Notes: cart_tax = cart_tax is the new name for the legacy 'order_tax' which is the tax for items only, not shipping.
$data_store_name string Which data store to load.
$items array Order items will be stored here, sometimes before they persist in the DB.
$items_to_delete array Order items that need deleting are stored here.

Méthodes publiques

Méthode Description
__construct ( integer | object | WC_Order $order ) Get the order if ID is passed, otherwise the order is new and empty.
add_item ( $item ) Adds an order item to this order. The order item will not persist until save.
add_payment_token ( WC_Payment_Token $token ) : boolean | integer Add a payment token to an order
add_product ( WC_Product $product, integer $qty = 1, array $args = [] ) : integer Add a product line item to the order. This is the only line item type with it's own method because it saves looking up order amounts (costs are added up for you).
calculate_shipping ( ) : float Calculate shipping total.
calculate_taxes ( $args = [] ) Calculate taxes for all line items and shipping, and store the totals and tax rows.
calculate_totals ( boolean $and_taxes = true ) : float Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
get_cart_tax ( string $context = 'view' ) : float Gets cart tax amount.
get_currency ( string $context = 'view' ) : string Gets order currency.
get_data ( ) : array Get all class data in array format.
get_date_created ( string $context = 'view' ) : integer Get date_created.
get_date_modified ( string $context = 'view' ) : integer Get date_modified.
get_discount_tax ( string $context = 'view' ) : string Get discount_tax.
get_discount_to_display ( $tax_display = '' ) : string Get the discount amount (formatted).
get_discount_total ( string $context = 'view' ) : string Get discount_total.
get_fees ( ) : array Return an array of fees within this order.
get_formatted_line_subtotal ( array $item, string $tax_display = '' ) : string Gets line subtotal - formatted for display.
get_formatted_order_total ( ) : string Gets order total - formatted for display.
get_item ( integer $item_id ) : WC_Order_Item Get an order item object, based on it's type.
get_item_count ( string $item_type = '' ) : string Gets the count of order items of a certain type.
get_item_subtotal ( object $item, boolean $inc_tax = false, boolean $round = true ) : float Get item subtotal - this is the cost before discount.
get_item_tax ( mixed $item, boolean $round = true ) : float Get item tax - useful for gateways.
get_item_total ( object $item, boolean $inc_tax = false, boolean $round = true ) : float Calculate item cost - useful for gateways.
get_items ( string | array $types = 'line_item' ) : Array Return an array of items/products within this order.
get_items_tax_classes ( ) : array Get all tax classes for items in the order.
get_line_subtotal ( object $item, boolean $inc_tax = false, boolean $round = true ) : float Get line subtotal - this is the cost before discount.
get_line_tax ( mixed $item ) : float Get line tax - useful for gateways.
get_line_total ( object $item, boolean $inc_tax = false, boolean $round = true ) : float Calculate line total - useful for gateways.
get_order_item_totals ( mixed $tax_display = '' ) : array Get totals for display on pages and in emails.
get_parent_id ( string $context = 'view' ) : integer Get parent order ID.
get_payment_tokens ( ) : array Returns a list of all payment tokens associated with the current order
get_prices_include_tax ( string $context = 'view' ) : boolean Get prices_include_tax.
get_shipping_method ( ) : string Gets formatted shipping method title.
get_shipping_methods ( ) : array Return an array of shipping costs within this order.
get_shipping_tax ( string $context = 'view' ) : string Get shipping_tax.
get_shipping_to_display ( $tax_display = '' ) : string Gets shipping (formatted).
get_shipping_total ( string $context = 'view' ) : string Get shipping_total.
get_status ( string $context = 'view' ) : string Return the order statuses without wc- internal prefix.
get_subtotal ( ) : float Gets order subtotal.
get_subtotal_to_display ( boolean $compound = false, string $tax_display = '' ) : string Gets subtotal - subtotal is shown before discounts, but with localised taxes.
get_tax_totals ( ) : array Get taxes, merged by code, formatted ready for output.
get_taxes ( ) : array Return an array of taxes within this order.
get_total ( string $context = 'view' ) : float Gets order grand total. incl. taxes. Used in gateways.
get_total_discount ( boolean $ex_tax = true ) : float Gets the total discount amount.
get_total_tax ( string $context = 'view' ) : float Get total tax amount. Alias for get_order_tax().
get_type ( ) : string Get internal type.
get_used_coupons ( ) : array Get coupon codes only.
get_version ( string $context = 'view' ) : string Get order_version.
has_free_item ( ) : boolean Returns true if the order contains a free product.
has_shipping_method ( string $method_id ) : boolean Check whether this order has a specific shipping method or not.
has_status ( $status ) : boolean Checks the order status against a passed in status.
remove_item ( integer $item_id ) Remove item from the order.
remove_order_items ( string $type = null ) Remove all line items (products, coupons, shipping, taxes) from the order.
save ( ) : integer Save data to the database.
set_cart_tax ( string $value ) Set cart tax.
set_currency ( string $value ) Set order_currency.
set_date_created ( string $timestamp ) Set date_created.
set_date_modified ( string $timestamp ) Set date_modified.
set_discount_tax ( string $value ) Set discount_tax.
set_discount_total ( string $value ) Set discount_total.
set_parent_id ( integer $value ) Set parent order ID.
set_prices_include_tax ( boolean $value ) Set prices_include_tax.
set_shipping_tax ( string $value ) Set shipping_tax.
set_shipping_total ( string $value ) Set shipping_total.
set_status ( string $new_status ) : array Set order status.
set_total ( string $value, string $deprecated = '' ) Set total.
set_version ( string $value ) Set order_version.
update_taxes ( ) Update tax lines for the order based on the line item taxes themselves.

Méthodes protégées

Méthode Description
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.
get_items_key ( $item ) : string Get key for where a certain item type is stored in _items.
save_items ( ) Save all order items which are part of this order.
set_total_tax ( string $value ) Sets order tax (sum of cart and shipping tax). Used internaly only.
type_to_group ( string $type ) : string Convert a type to a types group.

Method Details

__construct() public méthode

This class should NOT be instantiated, but the get_order function or new WC_Order_Factory. should be used. It is possible, but the aforementioned are preferred and are the only. methods that will be maintained going forward.
public __construct ( integer | object | WC_Order $order )
$order integer | object | WC_Order Order to read.

add_item() public méthode

Adds an order item to this order. The order item will not persist until save.
Since: 2.7.0
public add_item ( $item )

add_payment_token() public méthode

Add a payment token to an order
Since: 2.6
public add_payment_token ( WC_Payment_Token $token ) : boolean | integer
$token WC_Payment_Token Payment token object
Résultat boolean | integer The new token ID or false if it failed.

add_product() public méthode

Add a product line item to the order. This is the only line item type with it's own method because it saves looking up order amounts (costs are added up for you).
public add_product ( WC_Product $product, integer $qty = 1, array $args = [] ) : integer
$product WC_Product
$qty integer
$args array
Résultat integer order item ID

calculate_shipping() public méthode

Calculate shipping total.
Since: 2.2
public calculate_shipping ( ) : float
Résultat float

calculate_taxes() public méthode

Will use the base country unless customer addresses are set.
public calculate_taxes ( $args = [] )
$args array Added in 2.7.0 to pass things like location.

calculate_totals() public méthode

Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
Since: 2.2
public calculate_totals ( boolean $and_taxes = true ) : float
$and_taxes boolean Calc taxes if true.
Résultat float calculated grand total.

get_cart_tax() public méthode

Gets cart tax amount.
public get_cart_tax ( string $context = 'view' ) : float
$context string
Résultat float

get_currency() public méthode

Gets order currency.
public get_currency ( string $context = 'view' ) : string
$context string
Résultat string

get_data() public méthode

Get all class data in array format.
Since: 2.7.0
public get_data ( ) : array
Résultat array

get_date_created() public méthode

Get date_created.
public get_date_created ( string $context = 'view' ) : integer
$context string
Résultat integer

get_date_modified() public méthode

Get date_modified.
public get_date_modified ( string $context = 'view' ) : integer
$context string
Résultat integer

get_discount_tax() public méthode

Get discount_tax.
public get_discount_tax ( string $context = 'view' ) : string
$context string
Résultat string

get_discount_to_display() public méthode

Get the discount amount (formatted).
Since: 2.3.0
public get_discount_to_display ( $tax_display = '' ) : string
Résultat string

get_discount_total() public méthode

Get discount_total.
public get_discount_total ( string $context = 'view' ) : string
$context string
Résultat string

get_fees() public méthode

Return an array of fees within this order.
public get_fees ( ) : array
Résultat array

get_formatted_line_subtotal() public méthode

Gets line subtotal - formatted for display.
public get_formatted_line_subtotal ( array $item, string $tax_display = '' ) : string
$item array
$tax_display string
Résultat string

get_formatted_order_total() public méthode

Gets order total - formatted for display.
public get_formatted_order_total ( ) : string
Résultat string

get_hook_prefix() protected méthode

Prefix for action and filter hooks on data.
Since: 2.7.0
protected get_hook_prefix ( ) : string
Résultat string

get_item() public méthode

Get an order item object, based on it's type.
Since: 2.7.0
public get_item ( integer $item_id ) : WC_Order_Item
$item_id integer
Résultat WC_Order_Item

get_item_count() public méthode

Gets the count of order items of a certain type.
public get_item_count ( string $item_type = '' ) : string
$item_type string
Résultat string

get_item_subtotal() public méthode

Get item subtotal - this is the cost before discount.
public get_item_subtotal ( object $item, boolean $inc_tax = false, boolean $round = true ) : float
$item object
$inc_tax boolean (default: false).
$round boolean (default: true).
Résultat float

get_item_tax() public méthode

Get item tax - useful for gateways.
public get_item_tax ( mixed $item, boolean $round = true ) : float
$item mixed
$round boolean (default: true).
Résultat float

get_item_total() public méthode

Calculate item cost - useful for gateways.
public get_item_total ( object $item, boolean $inc_tax = false, boolean $round = true ) : float
$item object
$inc_tax boolean (default: false).
$round boolean (default: true).
Résultat float

get_items() public méthode

Return an array of items/products within this order.
public get_items ( string | array $types = 'line_item' ) : Array
$types string | array Types of line items to get (array or string).
Résultat Array of WC_Order_item

get_items_key() protected méthode

Get key for where a certain item type is stored in _items.
Since: 2.7.0
protected get_items_key ( $item ) : string
$item object Order item (product, shipping, fee, coupon, tax)
Résultat string

get_items_tax_classes() public méthode

Get all tax classes for items in the order.
Since: 2.6.3
public get_items_tax_classes ( ) : array
Résultat array

get_line_subtotal() public méthode

Get line subtotal - this is the cost before discount.
public get_line_subtotal ( object $item, boolean $inc_tax = false, boolean $round = true ) : float
$item object
$inc_tax boolean (default: false).
$round boolean (default: true).
Résultat float

get_line_tax() public méthode

Get line tax - useful for gateways.
public get_line_tax ( mixed $item ) : float
$item mixed
Résultat float

get_line_total() public méthode

Calculate line total - useful for gateways.
public get_line_total ( object $item, boolean $inc_tax = false, boolean $round = true ) : float
$item object
$inc_tax boolean (default: false).
$round boolean (default: true).
Résultat float

get_order_item_totals() public méthode

Get totals for display on pages and in emails.
public get_order_item_totals ( mixed $tax_display = '' ) : array
$tax_display mixed
Résultat array

get_parent_id() public méthode

Get parent order ID.
Since: 2.7.0
public get_parent_id ( string $context = 'view' ) : integer
$context string
Résultat integer

get_payment_tokens() public méthode

Returns a list of all payment tokens associated with the current order
Since: 2.6
public get_payment_tokens ( ) : array
Résultat array An array of payment token objects

get_prices_include_tax() public méthode

Get prices_include_tax.
public get_prices_include_tax ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_shipping_method() public méthode

Gets formatted shipping method title.
public get_shipping_method ( ) : string
Résultat string

get_shipping_methods() public méthode

Return an array of shipping costs within this order.
public get_shipping_methods ( ) : array
Résultat array

get_shipping_tax() public méthode

Get shipping_tax.
public get_shipping_tax ( string $context = 'view' ) : string
$context string
Résultat string

get_shipping_to_display() public méthode

Gets shipping (formatted).
public get_shipping_to_display ( $tax_display = '' ) : string
Résultat string

get_shipping_total() public méthode

Get shipping_total.
public get_shipping_total ( string $context = 'view' ) : string
$context string
Résultat string

get_status() public méthode

Return the order statuses without wc- internal prefix.
public get_status ( string $context = 'view' ) : string
$context string
Résultat string

get_subtotal() public méthode

Gets order subtotal.
public get_subtotal ( ) : float
Résultat float

get_subtotal_to_display() public méthode

Gets subtotal - subtotal is shown before discounts, but with localised taxes.
public get_subtotal_to_display ( boolean $compound = false, string $tax_display = '' ) : string
$compound boolean (default: false).
$tax_display string (default: the tax_display_cart value).
Résultat string

get_tax_totals() public méthode

Get taxes, merged by code, formatted ready for output.
public get_tax_totals ( ) : array
Résultat array

get_taxes() public méthode

Return an array of taxes within this order.
public get_taxes ( ) : array
Résultat array

get_total() public méthode

Gets order grand total. incl. taxes. Used in gateways.
public get_total ( string $context = 'view' ) : float
$context string
Résultat float

get_total_discount() public méthode

Gets the total discount amount.
public get_total_discount ( boolean $ex_tax = true ) : float
$ex_tax boolean Show discount excl any tax.
Résultat float

get_total_tax() public méthode

Get total tax amount. Alias for get_order_tax().
public get_total_tax ( string $context = 'view' ) : float
$context string
Résultat float

get_type() public méthode

Get internal type.
public get_type ( ) : string
Résultat string

get_used_coupons() public méthode

Get coupon codes only.
public get_used_coupons ( ) : array
Résultat array

get_version() public méthode

Get order_version.
public get_version ( string $context = 'view' ) : string
$context string
Résultat string

has_free_item() public méthode

Returns true if the order contains a free product.
Since: 2.5.0
public has_free_item ( ) : boolean
Résultat boolean

has_shipping_method() public méthode

Check whether this order has a specific shipping method or not.
public has_shipping_method ( string $method_id ) : boolean
$method_id string
Résultat boolean

has_status() public méthode

Checks the order status against a passed in status.
public has_status ( $status ) : boolean
Résultat boolean

remove_item() public méthode

Remove item from the order.
public remove_item ( integer $item_id )
$item_id integer

remove_order_items() public méthode

Remove all line items (products, coupons, shipping, taxes) from the order.
public remove_order_items ( string $type = null )
$type string Order item type. Default null.

save() public méthode

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

save_items() protected méthode

Save all order items which are part of this order.
protected save_items ( )

set_cart_tax() public méthode

Set cart tax.
public set_cart_tax ( string $value )
$value string

set_currency() public méthode

Set order_currency.
public set_currency ( string $value )
$value string

set_date_created() public méthode

Set date_created.
public set_date_created ( string $timestamp )
$timestamp string Timestamp

set_date_modified() public méthode

Set date_modified.
public set_date_modified ( string $timestamp )
$timestamp string

set_discount_tax() public méthode

Set discount_tax.
public set_discount_tax ( string $value )
$value string

set_discount_total() public méthode

Set discount_total.
public set_discount_total ( string $value )
$value string

set_parent_id() public méthode

Set parent order ID.
Since: 2.7.0
public set_parent_id ( integer $value )
$value integer

set_prices_include_tax() public méthode

Set prices_include_tax.
public set_prices_include_tax ( boolean $value )
$value boolean

set_shipping_tax() public méthode

Set shipping_tax.
public set_shipping_tax ( string $value )
$value string

set_shipping_total() public méthode

Set shipping_total.
public set_shipping_total ( string $value )
$value string

set_status() public méthode

Set order status.
Since: 2.7.0
public set_status ( string $new_status ) : array
$new_status string Status to change the order to. No internal wc- prefix is required.
Résultat array details of change

set_total() public méthode

Set total.
public set_total ( string $value, string $deprecated = '' )
$value string
$deprecated string Function used to set different totals based on this.

set_total_tax() protected méthode

Sets order tax (sum of cart and shipping tax). Used internaly only.
protected set_total_tax ( string $value )
$value string

set_version() public méthode

Set order_version.
public set_version ( string $value )
$value string

type_to_group() protected méthode

Convert a type to a types group.
protected type_to_group ( string $type ) : string
$type string
Résultat string group

update_taxes() public méthode

Update tax lines for the order based on the line item taxes themselves.
public update_taxes ( )

Property Details

$cache_group protected_oe property

A group must be set to to enable caching.
protected string $cache_group
Résultat string

$data protected_oe property

Notes: cart_tax = cart_tax is the new name for the legacy 'order_tax' which is the tax for items only, not shipping.
Since: 2.7.0
protected array $data
Résultat array

$data_store_name protected_oe property

Which data store to load.
protected string $data_store_name
Résultat string

$items protected_oe property

Order items will be stored here, sometimes before they persist in the DB.
Since: 2.7.0
protected array $items
Résultat array

$items_to_delete protected_oe property

Order items that need deleting are stored here.
Since: 2.7.0
protected array $items_to_delete
Résultat array