Skip to main content

Custom Pricing Methods

You can add custom pricing methods to PredictCart using the methods controller.

Architecture

Pricing methods are registered in PredictCart_Methods_Controller, which loads method classes from the classes/methods/ directory. Each method implements a specific pricing calculation (e.g., BOGO, group quantity).

Adding a Custom Method

Create a new method class and register it via predictcart_init_controllers:

add_action('predictcart_init_controllers', function() {
$controller = PredictCart_Methods_Controller::get_instance();
$controller->register_method('my_method', 'My_Namespace\My_Method');
});

Method Class Requirements

Each method class should provide:

  • calculate() — performs the pricing calculation
  • estimate_discount() — estimates the discount for stacking optimization
  • get_label() — human-readable name for the admin UI

Pricing Method Helpers

The PredictCart_Pricing class provides utility methods:

MethodDescription
apply_pricing_method($amount, $method, $value)Apply a pricing method to an amount
apply_volume_pricing_to_price($price, $cart_item, $rule)Apply volume/quantity pricing
estimate_rule_discount($cart_item, $rule, $cart_items)Estimate discount for a rule