Simple Commerce Logo

Dynamic Pricing

Depending on your use case, there may be situations where you need to use 'dynamic prices' for products depending on factors (eg. if customer is logged in, if customer is VIP, if it's a Friday, etc). Guess what - that's possible with Simple Commerce!

Essentially, the way it works is we provide a method for you to register a callback. Inside that callback you can do whatever decisioning you need to do to determine the price. I'd recommend adding this code to your app/Providers/AppServiceProvider.php, inside the boot method.

1use DoubleThreeDigital\SimpleCommerce\Contracts\Order;
2use DoubleThreeDigital\SimpleCommerce\Contracts\Product;
4SimpleCommerce::productPriceHook(function (Order $order, Product $product) {
5 if (now()->isWeekend()) {
6 return 1750;
7 }
9 return 1500;

Remember that you'll need to return the price as an integer. The above example returns £17.50 or £15.00 as prices.

An alternative method is also available for variant products.

1use DoubleThreeDigital\SimpleCommerce\Contracts\Order;
2use DoubleThreeDigital\SimpleCommerce\Contracts\Product;
3use DoubleThreeDigital\SimpleCommerce\Products\ProductVariant;
5SimpleCommerce::productVariantPriceHook(function (Order $order, Product $product, ProductVariant $variant) {
6 if (now()->isWeekend()) {
7 return 1750;
8 }
10 return 1500;

Note: These methods will not make any change to the price displayed to customers or stored in your products. They're only used when 'calculating' line items (eg. when an item is added to the cart, quantity changed, etc).

Code highlighting proudly provided by Torchlight.

Need some help?

There's plenty of ways of getting help: either via opening a GitHub Issue, starting a conversation on the Statamic Discord or directly emailing me.