Wholesale_Pro implements Registerable
Provides integration with the Wholesale Pro plugin.
Tags
Interfaces, Classes and Traits
- Registerable
Table of Contents
- $cart_handler : Cart
- The cart handler.
- $has_discounts : bool
- Whether the cart has discounts.
- $price_handler : Price_Handler
- The price handler from WWP.
- $products_handler : Products
- The products handler.
- clear_wholesale_pro_cache() : void
- Clear the Wholesale Pro cache because a discount has been updated.
- disable_if_user_has_discounts() : bool
- Disable the WWP price calculation if the user has user specific discounts.
- disable_multiple_triggers() : bool
- Disable multiple triggers for the wholesale price calculation.
- disable_wwp_hooks() : void
- Disable the WWP hooks that we don't need.
- enable_wholesale_price_calculation() : bool
- Disable the WWP price calculation if the user has a discount relevant to the product while having a wholesale discount at the same time.
- get_price_html() : string
- Get the price HTML for the product.
- register() : mixed
- set_admin_panel_description() : string
- Set the description for the Wholesale Pro admin panel.
- set_is_on_sale() : bool
- Set the is_on_sale flag for the product.
- calculate_price_with_both_discounts() : float
- Calculate the price with both the simple discount and the wholesale discount.
- get_category_wholesale_discount_amount() : float|bool
- Get the category wholesale discount amount for the product.
- get_global_wholesale_discount_amount() : float
- Get the global wholesale discount amount.
- product_has_simple_discount() : bool
- Check whether the product has a simple discount.
- product_has_wholesale_discount() : bool
- Check whether the product has a wholesale discount, this only checks whether the product has a category or global discount.
- product_has_wholesale_pricing() : bool
- Determine whether the product has a wholesale pricing.
- user_has_discount_relevant_to_product() : bool
- Check whether the user has a discount relevant to the product.
Properties
$cart_handler
The cart handler.
protected
Cart
$cart_handler
$has_discounts
Whether the cart has discounts.
protected
bool
$has_discounts
= false
$price_handler
The price handler from WWP.
protected
Price_Handler
$price_handler
$products_handler
The products handler.
protected
Products
$products_handler
Methods
clear_wholesale_pro_cache()
Clear the Wholesale Pro cache because a discount has been updated.
public
clear_wholesale_pro_cache() : void
Which means the prices may have changed for the wholesale roles and we need to clear the cache so the new prices are displayed.
Return values
void —disable_if_user_has_discounts()
Disable the WWP price calculation if the user has user specific discounts.
public
disable_if_user_has_discounts(bool $enabled, WC_Cart $cart, object $role) : bool
Parameters
- $enabled : bool
-
Whether the WWP price calculation is enabled.
- $cart : WC_Cart
-
The cart.
- $role : object
-
The wholesale role.
Return values
bool —disable_multiple_triggers()
Disable multiple triggers for the wholesale price calculation.
public
disable_multiple_triggers(bool $enabled, WC_Cart $cart, object $role) : bool
Parameters
- $enabled : bool
-
Whether the WWP price calculation is enabled.
- $cart : WC_Cart
-
The cart.
- $role : object
-
The wholesale role.
Return values
bool —disable_wwp_hooks()
Disable the WWP hooks that we don't need.
public
disable_wwp_hooks() : void
Return values
void —enable_wholesale_price_calculation()
Disable the WWP price calculation if the user has a discount relevant to the product while having a wholesale discount at the same time.
public
enable_wholesale_price_calculation(bool $enabled, WC_Product $product, WP_User|bool $user, float $price, array<string|int, mixed>|null $cart_item) : bool
Parameters
- $enabled : bool
-
Whether the WWP price calculation is enabled.
- $product : WC_Product
-
The product.
- $user : WP_User|bool
-
The user.
- $price : float
-
The price.
- $cart_item : array<string|int, mixed>|null
-
The cart item.
Return values
bool —get_price_html()
Get the price HTML for the product.
public
get_price_html(string $price_html, WC_Product $product) : string
We need to check whether the product has a simple discount and/or a wholesale discount. If there's only a simple discount then we need to fall back to the WDM price. If there's only a wholesale discount then we need to fall back to the WWP price. If there's both a simple discount and a wholesale discount then we need to calculate the final price.
Parameters
- $price_html : string
-
The current price HTML.
- $product : WC_Product
-
The product.
Return values
string —The new price HTML.
register()
public
register() : mixed
Tags
Return values
mixed —set_admin_panel_description()
Set the description for the Wholesale Pro admin panel.
public
set_admin_panel_description(string $description) : string
Parameters
- $description : string
-
The current description.
Return values
string —The new description.
set_is_on_sale()
Set the is_on_sale flag for the product.
public
set_is_on_sale(bool $is_on_sale, object $handler, string $role_name, WC_Product $product) : bool
Parameters
- $is_on_sale : bool
-
The current is_on_sale flag.
- $handler : object
-
The handler.
- $role_name : string
-
The role name.
- $product : WC_Product
-
The product.
Return values
bool —calculate_price_with_both_discounts()
Calculate the price with both the simple discount and the wholesale discount.
private
calculate_price_with_both_discounts(WC_Product $product, object $role) : float
Parameters
- $product : WC_Product
-
The product.
- $role : object
-
The wholesale role.
Return values
float —get_category_wholesale_discount_amount()
Get the category wholesale discount amount for the product.
private
get_category_wholesale_discount_amount(WC_Product $product, object $role) : float|bool
Parameters
- $product : WC_Product
-
The product.
- $role : object
-
The wholesale role.
Return values
float|bool —get_global_wholesale_discount_amount()
Get the global wholesale discount amount.
private
get_global_wholesale_discount_amount(object $role) : float
Parameters
- $role : object
-
The wholesale role.
Return values
float —product_has_simple_discount()
Check whether the product has a simple discount.
private
product_has_simple_discount(WC_Product $product) : bool
This is a discount powered by WDM.
Parameters
- $product : WC_Product
-
The product.
Return values
bool —product_has_wholesale_discount()
Check whether the product has a wholesale discount, this only checks whether the product has a category or global discount.
private
product_has_wholesale_discount(WC_Product $product, object $role) : bool
If the product has a wholesale pricing then this will return false.
Parameters
- $product : WC_Product
-
The product.
- $role : object
-
The wholesale role.
Return values
bool —product_has_wholesale_pricing()
Determine whether the product has a wholesale pricing.
private
product_has_wholesale_pricing(WC_Product $product, object $role) : bool
Parameters
- $product : WC_Product
-
The product.
- $role : object
-
The wholesale role.
Return values
bool —Whether the product has a wholesale pricing.
user_has_discount_relevant_to_product()
Check whether the user has a discount relevant to the product.
private
user_has_discount_relevant_to_product(int $user_id, int $product_id) : bool
Parameters
- $user_id : int
-
The user ID.
- $product_id : int
-
The product ID.