WooCommerce Code Reference

WC_Item_Totals

Trait WC_Item_Totals.

Right now this do not have much, but plan is to eventually move all shared calculation logic between Orders and Cart in this file.

Tags
since
3.9.0

Table of Contents

get_rounded_items_total()  : float|int
Return rounded total based on settings. Will be used by Cart and Orders.
round_item_subtotal()  : float
Apply rounding to item subtotal before summing.
get_values_for_total()  : array<string|int, mixed>
Line items to calculate. Define in child class.
round_at_subtotal()  : bool
Should always round at subtotal?
round_line_tax()  : float
Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.

Methods

get_rounded_items_total()

Return rounded total based on settings. Will be used by Cart and Orders.

public static get_rounded_items_total(array<string|int, mixed> $values) : float|int
Parameters
$values : array<string|int, mixed>

Values to round. Should be with precision.

Tags
since
3.9.0
Return values
float|intAppropriately rounded value.

round_item_subtotal()

Apply rounding to item subtotal before summing.

public static round_item_subtotal(float $value) : float
Parameters
$value : float

Item subtotal value.

Tags
since
3.9.0
Return values
float

get_values_for_total()

Line items to calculate. Define in child class.

protected abstract get_values_for_total(string $field) : array<string|int, mixed>
Parameters
$field : string

Field name to calculate upon.

Tags
since
3.9.0
Return values
array<string|int, mixed>having `total`|`subtotal` property.

round_line_tax()

Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.

protected static round_line_tax(float $value[, bool $in_cents = true ]) : float
Parameters
$value : float

Tax value.

$in_cents : bool = true

Whether precision of value is in cents.

Tags
since
3.2.6
Return values
float