Reference: Other Key Hooks & Filters
This document provides a technical reference for other important hooks and filters used in the plugin that are not covered in the main process flow documentation.
Dynamic Product Discounts (hooks/woo-product-discounts.php)
The plugin uses a flexible system to apply discounts dynamically based on user roles and product-specific settings.
Key Functions:
custom_dynamic_sale_price(): Hooks intowoocommerce_product_get_sale_priceto calculate a sale price on the fly.custom_dynamic_sale_price_html(): Hooks intowoocommerce_get_price_htmlto ensure the discounted price is displayed correctly on the frontend.set_cart_item_sale_price(): Hooks intowoocommerce_before_calculate_totalsto apply the final sale price to the item in the cart.
Discount Logic (WooHelper::getDiscountRate()):
The logic for determining the discount percentage is centralized in helpers/helpers-woo.php and follows this priority:
- Role Override: The system first checks if a
discount_overridepercentage is set for the user’s role on the Edge Store Settings → [Role Name] page. If a value exists, this discount is applied to all products for that user, and no further checks are made. This is the highest-priority discount. - Product-Specific Discount: If no role override is found, the system checks the individual product’s settings for a “Product Discounts” field (an ACF repeater field).
- Customer Group Match: It looks for a discount rule within the product’s settings where the “Customer Group” matches the current user’s role.
- Apply Percentage: If a matching rule is found, the
discount_percentfrom that rule is applied. - No Discount: If no override or matching rule is found, no discount is applied.
This two-tiered system allows for both broad, role-based discounts (like for desk copies) and targeted, product-specific promotions.
Other Notable Hooks
hooks/ct-new-order-email.php: This file contains logic for customizing the new order email notifications, potentially adding extra information related to ColourTech fulfilment.hooks/vitalsource-order.php: This hook likely contains the logic for fulfilling eBook orders via the VitalSource API, triggering after an order is completed.hooks/order-sync.php: This is a critical hook that initiates the entire order fulfillment and accounting sync process when an order’s status changes.