WooCommerce Code Reference

WC_Item_Totals

This ongoing trait will have shared calculation logic between WC_Abstract_Order and WC_Cart_Totals classes.

Tags
version
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
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 $values) : float|int
Parameters
$values : array

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
Parameters
$field : string

Field name to calculate upon.

Tags
since
3.9.0
Return values
arrayhaving `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