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 into woocommerce_product_get_sale_price to calculate a sale price on the fly.
  • custom_dynamic_sale_price_html(): Hooks into woocommerce_get_price_html to ensure the discounted price is displayed correctly on the frontend.
  • set_cart_item_sale_price(): Hooks into woocommerce_before_calculate_totals to 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:

  1. Role Override: The system first checks if a discount_override percentage 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.
  2. 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).
  3. Customer Group Match: It looks for a discount rule within the product’s settings where the “Customer Group” matches the current user’s role.
  4. Apply Percentage: If a matching rule is found, the discount_percent from that rule is applied.
  5. 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.