PHP Класс WC_Abstract_Order

The WooCommerce order class handles order data.
Автор: WooThemes
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

Adds an order item to this order. The order item will not persist until save.
С версии: 2.7.0
public add_item ( $item )

add_payment_token() публичный Метод

Add a payment token to an order
С версии: 2.6
public add_payment_token ( WC_Payment_Token $token ) : boolean | integer
$token WC_Payment_Token Payment token object
Результат boolean | integer The new token ID or false if it failed.

add_product() публичный Метод

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
Результат integer order item ID

calculate_shipping() публичный Метод

Calculate shipping total.
С версии: 2.2
public calculate_shipping ( ) : float
Результат float

calculate_taxes() публичный Метод

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() публичный Метод

Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
С версии: 2.2
public calculate_totals ( boolean $and_taxes = true ) : float
$and_taxes boolean Calc taxes if true.
Результат float calculated grand total.

get_cart_tax() публичный Метод

Gets cart tax amount.
public get_cart_tax ( string $context = 'view' ) : float
$context string
Результат float

get_currency() публичный Метод

Gets order currency.
public get_currency ( string $context = 'view' ) : string
$context string
Результат string

get_data() публичный Метод

Get all class data in array format.
С версии: 2.7.0
public get_data ( ) : array
Результат array

get_date_created() публичный Метод

Get date_created.
public get_date_created ( string $context = 'view' ) : integer
$context string
Результат integer

get_date_modified() публичный Метод

Get date_modified.
public get_date_modified ( string $context = 'view' ) : integer
$context string
Результат integer

get_discount_tax() публичный Метод

Get discount_tax.
public get_discount_tax ( string $context = 'view' ) : string
$context string
Результат string

get_discount_to_display() публичный Метод

Get the discount amount (formatted).
С версии: 2.3.0
public get_discount_to_display ( $tax_display = '' ) : string
Результат string

get_discount_total() публичный Метод

Get discount_total.
public get_discount_total ( string $context = 'view' ) : string
$context string
Результат string

get_fees() публичный Метод

Return an array of fees within this order.
public get_fees ( ) : array
Результат array

get_formatted_line_subtotal() публичный Метод

Gets line subtotal - formatted for display.
public get_formatted_line_subtotal ( array $item, string $tax_display = '' ) : string
$item array
$tax_display string
Результат string

get_formatted_order_total() публичный Метод

Gets order total - formatted for display.
public get_formatted_order_total ( ) : string
Результат string

get_hook_prefix() защищенный Метод

Prefix for action and filter hooks on data.
С версии: 2.7.0
protected get_hook_prefix ( ) : string
Результат string

get_item() публичный Метод

Get an order item object, based on it's type.
С версии: 2.7.0
public get_item ( integer $item_id ) : WC_Order_Item
$item_id integer
Результат WC_Order_Item

get_item_count() публичный Метод

Gets the count of order items of a certain type.
public get_item_count ( string $item_type = '' ) : string
$item_type string
Результат string

get_item_subtotal() публичный Метод

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).
Результат float

get_item_tax() публичный Метод

Get item tax - useful for gateways.
public get_item_tax ( mixed $item, boolean $round = true ) : float
$item mixed
$round boolean (default: true).
Результат float

get_item_total() публичный Метод

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).
Результат float

get_items() публичный Метод

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).
Результат Array of WC_Order_item

get_items_key() защищенный Метод

Get key for where a certain item type is stored in _items.
С версии: 2.7.0
protected get_items_key ( $item ) : string
$item object Order item (product, shipping, fee, coupon, tax)
Результат string

get_items_tax_classes() публичный Метод

Get all tax classes for items in the order.
С версии: 2.6.3
public get_items_tax_classes ( ) : array
Результат array

get_line_subtotal() публичный Метод

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).
Результат float

get_line_tax() публичный Метод

Get line tax - useful for gateways.
public get_line_tax ( mixed $item ) : float
$item mixed
Результат float

get_line_total() публичный Метод

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).
Результат float

get_order_item_totals() публичный Метод

Get totals for display on pages and in emails.
public get_order_item_totals ( mixed $tax_display = '' ) : array
$tax_display mixed
Результат array

get_parent_id() публичный Метод

Get parent order ID.
С версии: 2.7.0
public get_parent_id ( string $context = 'view' ) : integer
$context string
Результат integer

get_payment_tokens() публичный Метод

Returns a list of all payment tokens associated with the current order
С версии: 2.6
public get_payment_tokens ( ) : array
Результат array An array of payment token objects

get_prices_include_tax() публичный Метод

Get prices_include_tax.
public get_prices_include_tax ( string $context = 'view' ) : boolean
$context string
Результат boolean

get_shipping_method() публичный Метод

Gets formatted shipping method title.
public get_shipping_method ( ) : string
Результат string

get_shipping_methods() публичный Метод

Return an array of shipping costs within this order.
public get_shipping_methods ( ) : array
Результат array

get_shipping_tax() публичный Метод

Get shipping_tax.
public get_shipping_tax ( string $context = 'view' ) : string
$context string
Результат string

get_shipping_to_display() публичный Метод

Gets shipping (formatted).
public get_shipping_to_display ( $tax_display = '' ) : string
Результат string

get_shipping_total() публичный Метод

Get shipping_total.
public get_shipping_total ( string $context = 'view' ) : string
$context string
Результат string

get_status() публичный Метод

Return the order statuses without wc- internal prefix.
public get_status ( string $context = 'view' ) : string
$context string
Результат string

get_subtotal() публичный Метод

Gets order subtotal.
public get_subtotal ( ) : float
Результат float

get_subtotal_to_display() публичный Метод

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).
Результат string

get_tax_totals() публичный Метод

Get taxes, merged by code, formatted ready for output.
public get_tax_totals ( ) : array
Результат array

get_taxes() публичный Метод

Return an array of taxes within this order.
public get_taxes ( ) : array
Результат array

get_total() публичный Метод

Gets order grand total. incl. taxes. Used in gateways.
public get_total ( string $context = 'view' ) : float
$context string
Результат float

get_total_discount() публичный Метод

Gets the total discount amount.
public get_total_discount ( boolean $ex_tax = true ) : float
$ex_tax boolean Show discount excl any tax.
Результат float

get_total_tax() публичный Метод

Get total tax amount. Alias for get_order_tax().
public get_total_tax ( string $context = 'view' ) : float
$context string
Результат float

get_type() публичный Метод

Get internal type.
public get_type ( ) : string
Результат string

get_used_coupons() публичный Метод

Get coupon codes only.
public get_used_coupons ( ) : array
Результат array

get_version() публичный Метод

Get order_version.
public get_version ( string $context = 'view' ) : string
$context string
Результат string

has_free_item() публичный Метод

Returns true if the order contains a free product.
С версии: 2.5.0
public has_free_item ( ) : boolean
Результат boolean

has_shipping_method() публичный Метод

Check whether this order has a specific shipping method or not.
public has_shipping_method ( string $method_id ) : boolean
$method_id string
Результат boolean

has_status() публичный Метод

Checks the order status against a passed in status.
public has_status ( $status ) : boolean
Результат boolean

remove_item() публичный Метод

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

remove_order_items() публичный Метод

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() публичный Метод

Save data to the database.
С версии: 2.7.0
public save ( ) : integer
Результат integer order ID

save_items() защищенный Метод

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

set_cart_tax() публичный Метод

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

set_currency() публичный Метод

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

set_date_created() публичный Метод

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

set_date_modified() публичный Метод

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

set_discount_tax() публичный Метод

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

set_discount_total() публичный Метод

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

set_parent_id() публичный Метод

Set parent order ID.
С версии: 2.7.0
public set_parent_id ( integer $value )
$value integer

set_prices_include_tax() публичный Метод

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

set_shipping_tax() публичный Метод

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

set_shipping_total() публичный Метод

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

set_status() публичный Метод

Set order status.
С версии: 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.
Результат array details of change

set_total() публичный Метод

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() защищенный Метод

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

set_version() публичный Метод

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

type_to_group() защищенный Метод

Convert a type to a types group.
protected type_to_group ( string $type ) : string
$type string
Результат string group

update_taxes() публичный Метод

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

Описание свойств

$cache_group защищенное свойство

A group must be set to to enable caching.
protected string $cache_group
Результат string

$data защищенное свойство

Notes: cart_tax = cart_tax is the new name for the legacy 'order_tax' which is the tax for items only, not shipping.
С версии: 2.7.0
protected array $data
Результат array

$data_store_name защищенное свойство

Which data store to load.
protected string $data_store_name
Результат string

$items защищенное свойство

Order items will be stored here, sometimes before they persist in the DB.
С версии: 2.7.0
protected array $items
Результат array

$items_to_delete защищенное свойство

Order items that need deleting are stored here.
С версии: 2.7.0
protected array $items_to_delete
Результат array