PHP Class WC_API_Orders

Inheritance: extends WC_API_Resource
Exibir arquivo Open project: woocommerce/woocommerce

Protected Properties

Property Type Description
$base string the route base
$post_type string the custom post type

Public Methods

Method Description
bulk ( array $data ) : array Bulk update or insert orders Accepts an array with orders in the formats supported by WC_API_Orders->create_order() and WC_API_Orders->edit_order()
create_order ( array $data ) : array Create an order
create_order_note ( string $order_id, array $data ) : WP_Error | array Create a new order note for the given order
create_order_refund ( string $order_id, array $data, boolean $api_refund = true ) : WP_Error | array Create a new order refund for the given order
delete_order ( integer $id, boolean $force = false ) : array Delete an order
delete_order_note ( string $order_id, string $id ) : WP_Error | array Delete order note
delete_order_refund ( string $order_id, string $id ) : WP_Error | array Delete order refund
edit_order ( integer $id, array $data ) : array Edit an order
edit_order_note ( string $order_id, string $id, array $data ) : WP_Error | array Edit the order note
edit_order_refund ( string $order_id, string $id, array $data ) : WP_Error | array Edit an order refund
get_order ( integer $id, array $fields = null ) : array Get the order for the given ID
get_order ( integer $id, array $fields = null, array $filter = [] ) : array Get the order for the given ID.
get_order_note ( string $order_id, string $id, string | null $fields = null ) : array Get an order note for the given order ID and ID
get_order_notes ( integer $id, string $fields = null ) : array Get the admin order notes for an order
get_order_notes ( string $order_id, string | null $fields = null ) : array Get the admin order notes for an order
get_order_refund ( string $order_id, $id, string | null $fields = null ) : array Get an order refund for the given order ID and ID
get_order_refunds ( string $order_id, string | null $fields = null ) : array Get the order refunds for an order
get_order_statuses ( ) : array Get a list of valid order statuses
get_orders ( string $fields = null, array $filter = [], string $status = null, integer $page = 1 ) : array Get all orders
get_orders_count ( string $status = null, array $filter = [] ) : array Get the total number of orders
get_variation_id ( $product, $variations = [] ) : integer Given a product ID & API provided variations, find the correct variation ID to use for calculation We can't just trust input from the API to pass a variation_id manually, otherwise you could pass the cheapest variation ID but provide other information so we have to look up the variation ID.
get_variation_id ( WC_Product $product, $variations = [] ) : integer Given a product ID & API provided variations, find the correct variation ID to use for calculation We can't just trust input from the API to pass a variation_id manually, otherwise you could pass the cheapest variation ID but provide other information so we have to look up the variation ID.
register_routes ( array $routes ) : array Register the routes for this class

Protected Methods

Method Description
array_contains ( $needles, $haystack ) Utility function to see if the meta array contains data from variations
create_base_order ( $args, $data ) : WC_Order Creates new WC_Order.
item_is_null ( array $item ) : boolean Helper method to check if the resource ID associated with the provided item is null
query_orders ( array $args ) : WP_Query Helper method to get order post objects
set_coupon ( WC_Order $order, array $coupon, string $action ) Create or update an order coupon
set_fee ( WC_Order $order, array $fee, string $action ) Create or update an order fee
set_item ( WC_Order $order, string $item_type, array $item, string $action ) Wrapper method to create/update order items
set_line_item ( WC_Order $order, array $item, string $action ) Create or update a line item
set_order_addresses ( WC_Order $order, array $data ) Helper method to set/update the billing & shipping addresses for an order
set_order_meta ( integer $order_id, array $order_meta ) Helper method to add/update order meta, with two restrictions:
set_shipping ( WC_Order $order, array $shipping, string $action ) Create or update an order shipping method
update_address ( WC_Order $order, array $posted, string $type = 'billing' ) Update address.

Private Methods

Method Description
get_order_subtotal ( WC_Order $order ) : float Helper method to get the order subtotal

Method Details

array_contains() protected method

Utility function to see if the meta array contains data from variations
protected array_contains ( $needles, $haystack )

bulk() public method

Bulk update or insert orders Accepts an array with orders in the formats supported by WC_API_Orders->create_order() and WC_API_Orders->edit_order()
Since: 2.4.0
public bulk ( array $data ) : array
$data array
return array

create_base_order() protected method

Requires a separate function for classes that extend WC_API_Orders.
Since: 2.3
protected create_base_order ( $args, $data ) : WC_Order
$args array
return WC_Order

create_order() public method

Create an order
Since: 2.2
public create_order ( array $data ) : array
$data array raw order data
return array

create_order_note() public method

Create a new order note for the given order
Since: 2.2
public create_order_note ( string $order_id, array $data ) : WP_Error | array
$order_id string order ID
$data array raw request data
return WP_Error | array error or created note response data

create_order_refund() public method

Create a new order refund for the given order
Since: 2.2
public create_order_refund ( string $order_id, array $data, boolean $api_refund = true ) : WP_Error | array
$order_id string order ID
$data array raw request data
$api_refund boolean do refund using a payment gateway API
return WP_Error | array error or created refund response data

delete_order() public method

Delete an order
public delete_order ( integer $id, boolean $force = false ) : array
$id integer the order ID
$force boolean true to permanently delete order, false to move to trash
return array

delete_order_note() public method

Delete order note
Since: 2.2
public delete_order_note ( string $order_id, string $id ) : WP_Error | array
$order_id string order ID
$id string note ID
return WP_Error | array error or deleted message

delete_order_refund() public method

Delete order refund
Since: 2.2
public delete_order_refund ( string $order_id, string $id ) : WP_Error | array
$order_id string order ID
$id string refund ID
return WP_Error | array error or deleted message

edit_order() public method

Edit an order
Since: 2.2
public edit_order ( integer $id, array $data ) : array
$id integer the order ID
$data array
return array

edit_order_note() public method

Edit the order note
Since: 2.2
public edit_order_note ( string $order_id, string $id, array $data ) : WP_Error | array
$order_id string order ID
$id string note ID
$data array parsed request data
return WP_Error | array error or edited note response data

edit_order_refund() public method

Edit an order refund
Since: 2.2
public edit_order_refund ( string $order_id, string $id, array $data ) : WP_Error | array
$order_id string order ID
$id string refund ID
$data array parsed request data
return WP_Error | array error or edited refund response data

get_order() public method

Get the order for the given ID
Since: 2.1
public get_order ( integer $id, array $fields = null ) : array
$id integer the order ID
$fields array
return array

get_order() public method

Get the order for the given ID.
Since: 2.1
public get_order ( integer $id, array $fields = null, array $filter = [] ) : array
$id integer The order ID.
$fields array Request fields.
$filter array Request filters.
return array

get_order_note() public method

Get an order note for the given order ID and ID
Since: 2.2
public get_order_note ( string $order_id, string $id, string | null $fields = null ) : array
$order_id string order ID
$id string order note ID
$fields string | null fields to limit response to
return array

get_order_notes() public method

Get the admin order notes for an order
Since: 2.1
public get_order_notes ( integer $id, string $fields = null ) : array
$id integer the order ID
$fields string fields to include in response
return array

get_order_notes() public method

Get the admin order notes for an order
Since: 2.1
public get_order_notes ( string $order_id, string | null $fields = null ) : array
$order_id string order ID
$fields string | null fields to include in response
return array

get_order_refund() public method

Get an order refund for the given order ID and ID
Since: 2.2
public get_order_refund ( string $order_id, $id, string | null $fields = null ) : array
$order_id string order ID
$fields string | null fields to limit response to
return array

get_order_refunds() public method

Get the order refunds for an order
Since: 2.2
public get_order_refunds ( string $order_id, string | null $fields = null ) : array
$order_id string order ID
$fields string | null fields to include in response
return array

get_order_statuses() public method

Note this requires no specific permissions other than being an authenticated API user. Order statuses (particularly custom statuses) could be considered private information which is why it's not in the API index.
Since: 2.1
public get_order_statuses ( ) : array
return array

get_orders() public method

Get all orders
Since: 2.1
public get_orders ( string $fields = null, array $filter = [], string $status = null, integer $page = 1 ) : array
$fields string
$filter array
$status string
$page integer
return array

get_orders_count() public method

Get the total number of orders
Since: 2.4
public get_orders_count ( string $status = null, array $filter = [] ) : array
$status string
$filter array
return array

get_variation_id() public method

Given a product ID & API provided variations, find the correct variation ID to use for calculation We can't just trust input from the API to pass a variation_id manually, otherwise you could pass the cheapest variation ID but provide other information so we have to look up the variation ID.
public get_variation_id ( $product, $variations = [] ) : integer
return integer returns an ID if a valid variation was found for this product

get_variation_id() public method

Given a product ID & API provided variations, find the correct variation ID to use for calculation We can't just trust input from the API to pass a variation_id manually, otherwise you could pass the cheapest variation ID but provide other information so we have to look up the variation ID.
public get_variation_id ( WC_Product $product, $variations = [] ) : integer
$product WC_Product Product instance
return integer Returns an ID if a valid variation was found for this product

item_is_null() protected method

Items can be deleted by setting the resource ID to null
Since: 2.2
protected item_is_null ( array $item ) : boolean
$item array item provided in the request body
return boolean true if the item resource ID is null, false otherwise

query_orders() protected method

Helper method to get order post objects
Since: 2.1
protected query_orders ( array $args ) : WP_Query
$args array request arguments for filtering query
return WP_Query

register_routes() public method

GET|POST /orders GET /orders/count GET|PUT|DELETE /orders/ GET /orders//notes
Since: 2.1
public register_routes ( array $routes ) : array
$routes array
return array

set_coupon() protected method

Create or update an order coupon
Since: 2.2
protected set_coupon ( WC_Order $order, array $coupon, string $action )
$order WC_Order
$coupon array item data
$action string 'create' to add coupon or 'update' to update it

set_fee() protected method

Create or update an order fee
Since: 2.2
protected set_fee ( WC_Order $order, array $fee, string $action )
$order WC_Order
$fee array item data
$action string 'create' to add fee or 'update' to update it

set_item() protected method

When updating, the item ID provided is checked to ensure it is associated with the order.
Since: 2.2
protected set_item ( WC_Order $order, string $item_type, array $item, string $action )
$order WC_Order order
$item_type string
$item array item provided in the request body
$action string either 'create' or 'update'

set_line_item() protected method

Create or update a line item
Since: 2.2
protected set_line_item ( WC_Order $order, array $item, string $action )
$order WC_Order
$item array line item data
$action string 'create' to add line item or 'update' to update it

set_order_addresses() protected method

Helper method to set/update the billing & shipping addresses for an order
Since: 2.1
protected set_order_addresses ( WC_Order $order, array $data )
$order WC_Order
$data array

set_order_meta() protected method

1) Only non-protected meta (no leading underscore) can be set 2) Meta values must be scalar (int, string, bool)
Since: 2.2
protected set_order_meta ( integer $order_id, array $order_meta )
$order_id integer valid order ID
$order_meta array order meta in array( 'meta_key' => 'meta_value' ) format

set_shipping() protected method

Create or update an order shipping method
Since: 2.2
protected set_shipping ( WC_Order $order, array $shipping, string $action )
$order WC_Order
$shipping array item data
$action string 'create' to add shipping or 'update' to update it

update_address() protected method

Update address.
protected update_address ( WC_Order $order, array $posted, string $type = 'billing' )
$order WC_Order
$posted array
$type string

Property Details

$base protected_oe property

the route base
protected string $base
return string

$post_type protected_oe property

the custom post type
protected string $post_type
return string