Discount extends Entity implements IMappableEntity, JsonSerializable Uses Entity_ID, Entity_Assignable

Represents a discount created via the editor.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

IMappableEntity
JsonSerializable

Table of Contents

applies_to_everyone()  : bool
Determine if the discount is applicable to everyone.
applies_to_roles()  : bool
Determine if the discount is applicable to specific user roles.
applies_to_users()  : bool
Determine if the discount is applicable to specific users.
assign()  : self
Assign mass data to entity.
can_exclude_categories()  : bool
Determine if the discount can exclude categories.
can_exclude_products()  : bool
Determine if the discount can exclude products.
create()  : self
Create a new discount.
enabled()  : bool
Determine if the discount is enabled.
get_applicable_roles()  : array<string|int, mixed>
Get the list of user roles that the discount is applicable to.
get_applicable_users()  : array<string|int, mixed>
Get the list of users that the discount is applicable to.
get_availability_end_date()  : DateTime|null
Get the end date of the availability of the discount.
get_availability_start_date()  : DateTime|null
Get the start date of the availability of the discount.
get_elegible_categories()  : array<string|int, mixed>
Get the list of categories that the discount is applicable to.
get_elegible_products()  : array<string|int, mixed>
Get the list of products that the discount is applicable to.
get_elegible_variations()  : array<string|int, mixed>
Get the eligible variation IDs for this discount.
get_excluded_categories()  : array<string|int, mixed>
Return the list of categories that are excluded from the discount.
get_excluded_products()  : array<string|int, mixed>
Return the list of products that are excluded from the discount.
get_frontend_text()  : string
Get the content that may be displayed on the single product page.
get_frontend_text_location()  : string
Get the location where the content should be displayed on the single product page.
get_name()  : string
Get name of the discount.
get_notice()  : string
Returns the notice that should be displayed when the discount is applied.
get_relevant_products()  : array<string|int, mixed>
Get the products that are relevant to the discount from the cart.
get_slug()  : string
Get slug of the discount.
get_type()  : Type
Return the instance of the type of discount associated with this discount.
has_exclusions()  : bool
Determine if the discount has exclusions.
id()  : int
Retrieve ID of the Entity
is_always_available()  : bool
Determine if the discount is always available.
is_applicable_to_all_products()  : bool
Determine if the discount is applicable to all products.
is_applicable_to_cart()  : bool
Determine if the discount is applicable to the cart as a whole.
is_applicable_to_order()  : bool
Determine if the discount is applicable to the order as a whole.
is_applicable_to_specific_categories()  : bool
Determine if the discount is applicable to specific categories.
is_applicable_to_specific_products()  : bool
Determine if the discount is applicable to specific products.
is_applicable_to_specific_variations()  : bool
Determine if the discount is applicable to specific products with specific variations.
is_available_between_dates()  : bool
Determine if the discount is available between specific dates.
is_discount_available_today()  : bool
Determine if the discount is available today.
is_relevant_for_product()  : bool
Determine if the discount is relevant for a specific product.
jsonSerialize()  : mixed
List of properties usually used via the rest api.
mapEntity()  : mixed
priority()  : int
Get the priority order number of the discount.
product_name_with_selected_variations()  : string
Get the product name with selected variations appended.
set_enabled()  : self
Set the discount enabled or disabled.
set_id()  : void
Set ID of the Entity
set_name()  : self
Set name of the discount.
set_priority()  : self
Set the discount enabled or disabled.
set_slug()  : self
Set slug of the discount.
settings()  : Collection
Get settings associated with the discount.
filter_products_by_specific_variations()  : array<string|int, mixed>
Filter products by specific variations.
get_application_column_content()  : string
Get the content of the application column in the admin area.
prepare_settings_for_table()  : array<string|int, mixed>
Prepares the settings for the table.

Methods

applies_to_everyone()

Determine if the discount is applicable to everyone.

public applies_to_everyone() : bool
Return values
bool

applies_to_roles()

Determine if the discount is applicable to specific user roles.

public applies_to_roles() : bool
Return values
bool

applies_to_users()

Determine if the discount is applicable to specific users.

public applies_to_users() : bool
Return values
bool

assign()

Assign mass data to entity.

public assign(array<string|int, mixed> $data) : self
Parameters
$data : array<string|int, mixed>
Return values
self

can_exclude_categories()

Determine if the discount can exclude categories.

public can_exclude_categories() : bool
Return values
bool

can_exclude_products()

Determine if the discount can exclude products.

public can_exclude_products() : bool
Return values
bool

create()

Create a new discount.

public static create([array<string|int, mixed> $args = [] ]) : self
Parameters
$args : array<string|int, mixed> = []

The discount arguments.

Return values
self

The new discount.

enabled()

Determine if the discount is enabled.

public enabled() : bool
Return values
bool

get_applicable_roles()

Get the list of user roles that the discount is applicable to.

public get_applicable_roles() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_applicable_users()

Get the list of users that the discount is applicable to.

public get_applicable_users() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_availability_end_date()

Get the end date of the availability of the discount.

public get_availability_end_date() : DateTime|null
Return values
DateTime|null

get_availability_start_date()

Get the start date of the availability of the discount.

public get_availability_start_date() : DateTime|null
Return values
DateTime|null

get_elegible_categories()

Get the list of categories that the discount is applicable to.

public get_elegible_categories() : array<string|int, mixed>

This includes the children categories.

Return values
array<string|int, mixed>

get_elegible_products()

Get the list of products that the discount is applicable to.

public get_elegible_products() : array<string|int, mixed>

This method does not include the variations.

Return values
array<string|int, mixed>

get_elegible_variations()

Get the eligible variation IDs for this discount.

public get_elegible_variations() : array<string|int, mixed>

This method retrieves the variation IDs that are eligible for the discount when the discount is applicable to specific variations of variable products.

Return values
array<string|int, mixed>

An array of unique variation IDs that are eligible for the discount. Returns an empty array if the discount is not applicable to specific variations or if no variations are selected.

get_excluded_categories()

Return the list of categories that are excluded from the discount.

public get_excluded_categories() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_excluded_products()

Return the list of products that are excluded from the discount.

public get_excluded_products() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_frontend_text()

Get the content that may be displayed on the single product page.

public get_frontend_text() : string
Return values
string

get_frontend_text_location()

Get the location where the content should be displayed on the single product page.

public get_frontend_text_location() : string
Return values
string

get_name()

Get name of the discount.

public get_name() : string
Return values
string

get_notice()

Returns the notice that should be displayed when the discount is applied.

public get_notice() : string
Return values
string

get_relevant_products()

Get the products that are relevant to the discount from the cart.

public get_relevant_products([WC_Cart|false $cart = false ][, WC_Order|false $order = false ][, bool $sort = true ]) : array<string|int, mixed>

Products are relevant if they are elegible for the discount and not excluded from the discount. Products are retrieved based on the discount applicability and the discount exclusions.

If an order is provided, the products will be retrieved from the order instead of the cart.

Parameters
$cart : WC_Cart|false = false

The cart object.

$order : WC_Order|false = false

The order object. If provided, the products will be retrieved from the order instead of the cart.

$sort : bool = true

Whether to sort the products by price. Defaults to true.

Tags
throws
Exception

If neither a cart nor an order is provided.

Return values
array<string|int, mixed>

The products that are relevant to the discount.

get_slug()

Get slug of the discount.

public get_slug() : string
Return values
string

get_type()

Return the instance of the type of discount associated with this discount.

public get_type() : Type
Tags
throws
Exception

If the type is not found or does not have a class.

Return values
Type

has_exclusions()

Determine if the discount has exclusions.

public has_exclusions() : bool
Return values
bool

id()

Retrieve ID of the Entity

public id() : int
Return values
int

is_always_available()

Determine if the discount is always available.

public is_always_available() : bool
Return values
bool

is_applicable_to_all_products()

Determine if the discount is applicable to all products.

public is_applicable_to_all_products() : bool
Return values
bool

is_applicable_to_cart()

Determine if the discount is applicable to the cart as a whole.

public is_applicable_to_cart(WC_Cart $cart) : bool
Parameters
$cart : WC_Cart

The cart object.

Return values
bool

True if the discount is applicable to the cart as a whole.

is_applicable_to_order()

Determine if the discount is applicable to the order as a whole.

public is_applicable_to_order(WC_Order $order) : bool
Parameters
$order : WC_Order

The order object.

Return values
bool

True if the discount is applicable to the order as a whole.

is_applicable_to_specific_categories()

Determine if the discount is applicable to specific categories.

public is_applicable_to_specific_categories() : bool
Return values
bool

is_applicable_to_specific_products()

Determine if the discount is applicable to specific products.

public is_applicable_to_specific_products() : bool
Return values
bool

is_applicable_to_specific_variations()

Determine if the discount is applicable to specific products with specific variations.

public is_applicable_to_specific_variations() : bool
Return values
bool

is_available_between_dates()

Determine if the discount is available between specific dates.

public is_available_between_dates() : bool
Return values
bool

is_discount_available_today()

Determine if the discount is available today.

public is_discount_available_today() : bool
Return values
bool

is_relevant_for_product()

Determine if the discount is relevant for a specific product.

public is_relevant_for_product(string|bool|int|WC_Product $product) : bool
Parameters
$product : string|bool|int|WC_Product

The product object.

Return values
bool

True if the discount is relevant for the product.

jsonSerialize()

List of properties usually used via the rest api.

public jsonSerialize() : mixed
Return values
mixed

mapEntity()

public static mapEntity(IEntityMapper $mapper) : mixed
Parameters
$mapper : IEntityMapper
Tags
inheritdoc
Return values
mixed

priority()

Get the priority order number of the discount.

public priority() : int
Return values
int

product_name_with_selected_variations()

Get the product name with selected variations appended.

public product_name_with_selected_variations(WC_Product $product) : string

This method takes a product object and appends the names of selected variations to the product name, if any variations are selected for this discount.

Parameters
$product : WC_Product

The product object.

Return values
string

The product name, potentially with selected variations appended.

set_enabled()

Set the discount enabled or disabled.

public set_enabled(bool $enabled) : self
Parameters
$enabled : bool
Return values
self

set_id()

Set ID of the Entity

public set_id(int|string|null $id) : void
Parameters
$id : int|string|null

ID of the Entity

Return values
void

set_name()

Set name of the discount.

public set_name(string $name) : self
Parameters
$name : string
Return values
self

set_priority()

Set the discount enabled or disabled.

public set_priority(int $priority) : self
Parameters
$priority : int
Return values
self

set_slug()

Set slug of the discount.

public set_slug(string $slug) : self
Parameters
$slug : string
Return values
self

settings()

Get settings associated with the discount.

public settings() : Collection
Return values
Collection

filter_products_by_specific_variations()

Filter products by specific variations.

private filter_products_by_specific_variations(mixed $cart_items) : array<string|int, mixed>

This method supports filtering both cart items and order items.

Parameters
$cart_items : mixed
Return values
array<string|int, mixed>

The filtered array of items.

get_application_column_content()

Get the content of the application column in the admin area.

private get_application_column_content() : string
Return values
string

The content of the application column.

prepare_settings_for_table()

Prepares the settings for the table.

private prepare_settings_for_table() : array<string|int, mixed>

This is used to display the settings in the admin area and to prepare the settings for the rest api which is used by the react app and may require extra data.

Return values
array<string|int, mixed>

The settings.

Search results