Reduction

Base reduction class that represents the pricing adjustments that a discount can make.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$amount  : float
The amount of the reduction.
$discount  : Discount
The discount responsible for the reduction.
$sale_price  : float
Force a specific sale price instead of calculating it.
__construct()  : mixed
Reduction constructor.
apply_reduction()  : void
Apply the reduction to the given product.
apply_reduction_to_order_item()  : void
Apply the reduction to the given order item.
get_amount()  : float
Get the amount of the reduction.
get_discount()  : Discount|null
Get the discount responsible for the reduction.
get_sale_price()  : float
Get the forced sale price.
get_total_reduction_for_order()  : float
Calculate the total reduction for the given order.
has_discount()  : bool
Determine if the reduction has a discount entity.
has_sale_price()  : bool
Determine if the reduction has a forced sale price.
set_amount()  : self
Set the amount of the reduction.
set_cart_item_data()  : void
Set the cart item data. This is used to store the original and new prices of the cart item.
set_discount()  : self
Set the discount responsible for the reduction.
set_sale_price()  : self
Set the forced sale price.

Properties

$amount

The amount of the reduction.

protected float $amount

$sale_price

Force a specific sale price instead of calculating it.

protected float $sale_price

Methods

__construct()

Reduction constructor.

public __construct(float $amount[, float|null $sale_price = null ][, mixed $discount = null ]) : mixed
Parameters
$amount : float

The amount of the reduction.

$sale_price : float|null = null

Optional. Force a specific sale price instead of calculating it.

$discount : mixed = null

Optional. The discount responsible for the reduction.

Return values
mixed

apply_reduction()

Apply the reduction to the given product.

public abstract apply_reduction(WC_Product &$product[, array<string|int, mixed> &$cart_item = [] ]) : void
Parameters
$product : WC_Product
$cart_item : array<string|int, mixed> = []

Optional. The cart item.

Return values
void

apply_reduction_to_order_item()

Apply the reduction to the given order item.

public abstract apply_reduction_to_order_item(WC_Order_Item_Product &$item) : void
Parameters
$item : WC_Order_Item_Product
Return values
void

get_amount()

Get the amount of the reduction.

public get_amount() : float
Return values
float

get_discount()

Get the discount responsible for the reduction.

public get_discount() : Discount|null
Return values
Discount|null

get_sale_price()

Get the forced sale price.

public get_sale_price() : float
Return values
float

get_total_reduction_for_order()

Calculate the total reduction for the given order.

public abstract get_total_reduction_for_order(array<string|int, WC_Order_Item_Product$order_items) : float

The total reduction is the sum of all reductions applied to the items in the order.

The reduction is then returned as a float.

This is used to then generate a negative fee for the order.

Parameters
$order_items : array<string|int, WC_Order_Item_Product>
Return values
float

has_discount()

Determine if the reduction has a discount entity.

public has_discount() : bool
Return values
bool

has_sale_price()

Determine if the reduction has a forced sale price.

public has_sale_price() : bool
Return values
bool

set_amount()

Set the amount of the reduction.

public set_amount(float $amount) : self
Parameters
$amount : float
Return values
self

set_cart_item_data()

Set the cart item data. This is used to store the original and new prices of the cart item.

public set_cart_item_data(array<string|int, mixed> &$cart_item, float $original_price, float $new_price) : void
Parameters
$cart_item : array<string|int, mixed>

The cart item.

$original_price : float

The original price.

$new_price : float

The new price.

Return values
void

set_discount()

Set the discount responsible for the reduction.

public set_discount(Discount $discount) : self
Parameters
$discount : Discount
Return values
self

set_sale_price()

Set the forced sale price.

public set_sale_price(float $sale_price) : self
Parameters
$sale_price : float
Return values
self

Search results