Orders implements Registerable

Handles integration with WooCommerce orders when manually creating an order from the admin.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

Registerable

Table of Contents

add_order_item_totals()  : array<string|int, mixed>
Add the total savings to the order item totals.
calculate_order_discount()  : void
Calculate the discount for the given order.
display_total_savings()  : void
Display the total savings in the order totals.
format_item_data()  : string
Format the metadata value so that it is displayed in a human-readable format.
format_item_key()  : string
Format the metadata key so that it is displayed in a human-readable format.
get_applicable_discounts()  : array<string|int, mixed>
Get all discounts that should be applied to the given order.
get_discounted_items()  : array<string|int, mixed>
Get the discounted items in the order.
get_products_ids()  : array<string|int, mixed>
Get the products ids in the order.
get_products_in_categories()  : array<string|int, mixed>
Get the products with a class of WC_Order_Item_Product in the order but only if they are in the given categories.
get_specific_products()  : array<string|int, mixed>
Get the specific products in the order with the class of \WC_Order_Item_Product but only if they are in the given products array.
get_total_savings()  : float
Get the total savings of the order.
has_products_in_categories()  : bool
Determine if the given order has any products in the given categories.
has_specific_products()  : bool
Check if the given order has any of the given products.
hide_metadata()  : array<string|int, mixed>
Hide the "_wdm_discounted" keys from the order item meta data.
purge_discounts()  : void
Purge the discounts meta data from the order.
register()  : void
register_custom_order_action()  : array<string|int, mixed>
Register the custom order action.
save_discount_metadata()  : mixed
Save the "_wdm_discounted", "_wdm_discounted_by" and "_wdm" keys as a meta data.
save_discounts_list_metadata()  : void
Save the list of active discounts as a meta data.
maybe_purge_coupons()  : void
Purge any coupons that start with 'wdm-discount'.

Methods

add_order_item_totals()

Add the total savings to the order item totals.

public add_order_item_totals(array<string|int, mixed> $total_rows, WC_Order $order) : array<string|int, mixed>
Parameters
$total_rows : array<string|int, mixed>

The total rows.

$order : WC_Order

The order.

Return values
array<string|int, mixed>

calculate_order_discount()

Calculate the discount for the given order.

public calculate_order_discount(WC_Order $order) : void
Parameters
$order : WC_Order
Return values
void

display_total_savings()

Display the total savings in the order totals.

public display_total_savings(int $order_id) : void
Parameters
$order_id : int

The order ID.

Return values
void

format_item_data()

Format the metadata value so that it is displayed in a human-readable format.

public format_item_data(string $value, WC_Meta_Data $meta, WC_Order_Item_Product $item) : string
Parameters
$value : string

The value.

$meta : WC_Meta_Data

The meta data.

$item : WC_Order_Item_Product

The order item.

Return values
string

format_item_key()

Format the metadata key so that it is displayed in a human-readable format.

public format_item_key(string $key, WC_Meta_Data $meta, WC_Order_Item_Product $item) : string
Parameters
$key : string

The key.

$meta : WC_Meta_Data

The meta data.

$item : WC_Order_Item_Product

The order item.

Return values
string

get_applicable_discounts()

Get all discounts that should be applied to the given order.

public get_applicable_discounts(WC_Order $order) : array<string|int, mixed>
Parameters
$order : WC_Order
Return values
array<string|int, mixed>

get_discounted_items()

Get the discounted items in the order.

public get_discounted_items(WC_Order $order) : array<string|int, mixed>
Parameters
$order : WC_Order

The order.

Return values
array<string|int, mixed>

get_products_ids()

Get the products ids in the order.

public static get_products_ids(WC_Order $order) : array<string|int, mixed>
Parameters
$order : WC_Order
Return values
array<string|int, mixed>

get_products_in_categories()

Get the products with a class of WC_Order_Item_Product in the order but only if they are in the given categories.

public static get_products_in_categories(WC_Order $order, array<string|int, mixed> $categories) : array<string|int, mixed>

If the product is a variation, the parent product is checked.

Parameters
$order : WC_Order

The order to check.

$categories : array<string|int, mixed>

The categories to find.

Return values
array<string|int, mixed>

The products found in the order.

get_specific_products()

Get the specific products in the order with the class of \WC_Order_Item_Product but only if they are in the given products array.

public static get_specific_products(WC_Order $order, array<string|int, mixed> $products) : array<string|int, mixed>

If the product is a variation, the parent product is checked.

Parameters
$order : WC_Order

The order to check.

$products : array<string|int, mixed>

The products to find.

Return values
array<string|int, mixed>

The products found in the order.

get_total_savings()

Get the total savings of the order.

public get_total_savings(WC_Order $order) : float
Parameters
$order : WC_Order

The order.

Return values
float

has_products_in_categories()

Determine if the given order has any products in the given categories.

public static has_products_in_categories(WC_Order $order, array<string|int, mixed> $categories) : bool
Parameters
$order : WC_Order

The order to check.

$categories : array<string|int, mixed>

The categories to check.

Return values
bool

True if the order has any products in the given categories, false otherwise.

has_specific_products()

Check if the given order has any of the given products.

public static has_specific_products(WC_Order $order, array<string|int, mixed> $products) : bool
Parameters
$order : WC_Order

The order to check.

$products : array<string|int, mixed>

The products to check.

Return values
bool

True if the order has any of the given products, false otherwise.

hide_metadata()

Hide the "_wdm_discounted" keys from the order item meta data.

public hide_metadata(array<string|int, mixed> $hidden) : array<string|int, mixed>
Parameters
$hidden : array<string|int, mixed>

The hidden keys.

Return values
array<string|int, mixed>

purge_discounts()

Purge the discounts meta data from the order.

public purge_discounts(WC_Order $order) : void

This is used when the order is updated and recalculation is needed. This also removes the metadata from each order item.

Parameters
$order : WC_Order

The order.

Return values
void

register()

public register() : void
Tags
inheritdoc
Return values
void

register_custom_order_action()

Register the custom order action.

public register_custom_order_action(array<string|int, mixed> $actions, WC_Order $order) : array<string|int, mixed>
Parameters
$actions : array<string|int, mixed>

The list of actions.

$order : WC_Order

The order.

Return values
array<string|int, mixed>

save_discount_metadata()

Save the "_wdm_discounted", "_wdm_discounted_by" and "_wdm" keys as a meta data.

public save_discount_metadata(WC_Order_Item_Product $item, string $cart_item_key, array<string|int, mixed> $values, WC_Order $order) : mixed
Parameters
$item : WC_Order_Item_Product

The order item.

$cart_item_key : string

The cart item key.

$values : array<string|int, mixed>

The values.

$order : WC_Order

The order.

Return values
mixed

save_discounts_list_metadata()

Save the list of active discounts as a meta data.

public save_discounts_list_metadata(WC_Order $order) : void
Parameters
$order : WC_Order

The order.

Return values
void

maybe_purge_coupons()

Purge any coupons that start with 'wdm-discount'.

private maybe_purge_coupons(WC_Order $order) : void
Parameters
$order : WC_Order
Return values
void

Search results