Validator
Class that helps validating settings submitted when creating discounts through the admin panel.
Tags
Table of Contents
- $data : Collection
- Collection of data submitted.
- $errors : WP_Error
- List of errors found.
- __construct() : mixed
- Initialize the validator by storing the data submitted.
- add_error() : self
- Add an error to the list.
- get_error_message() : string
- Retrieves all error messages.
- has_errors() : bool
- Determine if the validator has found errors.
- validate() : self
- Validate submitted data.
- validate_applies_to() : void
- Validate the "Applies to" field.
- validate_availability() : void
- Validate the "Availability" dates field.
- validate_empty_property() : void
- Validate that a property isn't empty.
- validate_name() : void
- Validate the discount type.
- validate_type() : void
- Validate the "discount type" field.
- validate_type_setting_additional_qty() : void
- Validate the "additional quantity" field.
- validate_type_setting_amount_type() : void
- Validate the "Discount" field.
- validate_type_setting_apply_to() : void
- Validate the "apply to" field.
- validate_type_setting_fixed_discount() : void
- Validate the fixed discount amount field.
- validate_type_setting_fixed_price() : void
- Validate the "fixed price" field.
- validate_type_setting_free_product() : void
- Validate the "free product" field.
- validate_type_setting_free_qty() : void
- Validate the "free quantity" field.
- validate_type_setting_percentage_discount() : void
- Validate the percentage discount amount field.
- validate_type_setting_range_type() : void
- Validate the "range type" field.
- validate_type_setting_required_qty() : void
- Validate the "required quantity" field.
- validate_type_setting_tiers() : void
- Validate the "tiers" field.
- validate_type_setting_total_spend() : void
- Validate the "total spend" field.
- validate_which_products() : void
- Validate which products are selected.
Properties
$data
Collection of data submitted.
protected
Collection
$data
$errors
List of errors found.
protected
WP_Error
$errors
Methods
__construct()
Initialize the validator by storing the data submitted.
public
__construct(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
Return values
mixed —add_error()
Add an error to the list.
public
add_error(string $code, string $message) : self
Parameters
- $code : string
- $message : string
Return values
self —get_error_message()
Retrieves all error messages.
public
get_error_message() : string
Return values
string —has_errors()
Determine if the validator has found errors.
public
has_errors() : bool
Return values
bool —validate()
Validate submitted data.
public
validate() : self
Return values
self —validate_applies_to()
Validate the "Applies to" field.
private
validate_applies_to() : void
Return values
void —validate_availability()
Validate the "Availability" dates field.
private
validate_availability() : void
Return values
void —validate_empty_property()
Validate that a property isn't empty.
private
validate_empty_property(string $property, string $message) : void
Parameters
- $property : string
- $message : string
Return values
void —validate_name()
Validate the discount type.
private
validate_name() : void
Return values
void —validate_type()
Validate the "discount type" field.
private
validate_type() : void
This will also validate the settings for the selected discount type.
Return values
void —validate_type_setting_additional_qty()
Validate the "additional quantity" field.
private
validate_type_setting_additional_qty(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_amount_type()
Validate the "Discount" field.
private
validate_type_setting_amount_type(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_apply_to()
Validate the "apply to" field.
private
validate_type_setting_apply_to(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_fixed_discount()
Validate the fixed discount amount field.
private
validate_type_setting_fixed_discount(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_fixed_price()
Validate the "fixed price" field.
private
validate_type_setting_fixed_price(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_free_product()
Validate the "free product" field.
private
validate_type_setting_free_product(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_free_qty()
Validate the "free quantity" field.
private
validate_type_setting_free_qty(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_percentage_discount()
Validate the percentage discount amount field.
private
validate_type_setting_percentage_discount(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_range_type()
Validate the "range type" field.
private
validate_type_setting_range_type(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_required_qty()
Validate the "required quantity" field.
private
validate_type_setting_required_qty(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_tiers()
Validate the "tiers" field.
private
validate_type_setting_tiers(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_type_setting_total_spend()
Validate the "total spend" field.
private
validate_type_setting_total_spend(string $value) : void
Parameters
- $value : string
-
The value of the field.
Return values
void —validate_which_products()
Validate which products are selected.
private
validate_which_products() : void