WooCommerce Code Reference

WC_Cart_Fees
in package

WC_Cart_Fees class.

Tags
since
3.2.0

Table of Contents

$cart  : WC_Cart
Reference to cart object.
$default_fee_props  : array
New fees are made out of these props.
$fees  : object[]
An array of fee objects.
__construct()  : mixed
Constructor. Reference to the cart.
add_fee()  : object
Add a fee. Fee IDs must be unique.
get_fees()  : array
Get fees.
init()  : mixed
Register methods for this object on the appropriate WordPress hooks.
remove_all_fees()  : mixed
Remove all fees.
set_fees()  : mixed
Set fees.
sort_fees_callback()  : int
Sort fees by amount.
generate_id()  : string
Generate a unique ID for the fee being added.

Properties

$default_fee_props

New fees are made out of these props.

private array $default_fee_props = array('id' => '', 'name' => '', 'tax_class' => '', 'taxable' => alse, 'amount' => 0, 'total' => 0)

Methods

__construct()

Constructor. Reference to the cart.

public __construct(WC_Cart &$cart) : mixed
Parameters
$cart : WC_Cart

Cart object.

Tags
since
3.2.0
throws
Exception

If missing WC_Cart object.

Return values
mixed

add_fee()

Add a fee. Fee IDs must be unique.

public add_fee([array $args = array() ]) : object
Parameters
$args : array = array()

Array of fee properties.

Tags
since
3.2.0
Return values
objectEither a fee object if added, or a WP_Error if it failed.

init()

Register methods for this object on the appropriate WordPress hooks.

public init() : mixed
Return values
mixed

set_fees()

Set fees.

public set_fees([object[] $raw_fees = array() ]) : mixed
Parameters
$raw_fees : object[] = array()

Array of fees.

Return values
mixed

sort_fees_callback()

Sort fees by amount.

protected sort_fees_callback(stdClass $a, stdClass $b) : int
Parameters
$a : stdClass

Fee object.

$b : stdClass

Fee object.

Return values
int

generate_id()

Generate a unique ID for the fee being added.

private generate_id(string $fee) : string
Parameters
$fee : string

Fee object.

Return values
stringfee key.