WooCommerce Code Reference

Search results

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.

Table of Contents

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

Methods

get_values_for_total()

Line items to calculate. Define in child class.

protected abstract get_values_for_total( $field : string ) : array
Parameters
$field : string

Field name to calculate upon.

Tags
since
Return values
array

having total|subtotal property.

get_rounded_items_total()

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

public static get_rounded_items_total( $values : array ) : float|int
Parameters
$values : array

Values to round. Should be with precision.

Tags
since
Return values
float|int

Appropriately rounded value.

round_item_subtotal()

Apply rounding to item subtotal before summing.

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

Item subtotal value.

Tags
since
Return values
float

round_at_subtotal()

Should always round at subtotal?

protected static round_at_subtotal( ) : bool
Tags
since
Return values
bool

round_line_tax()

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

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

Tax value.

$in_cents : bool = true

Whether precision of value is in cents.

Tags
since
Return values
float
Back to the top