In this blog, we are going to learn how to override a product price calculation in PrestaShop.
Usually, we use the default price of the product for the customers. Sometimes we need to override the price of the product. This price can be used for every customer or some specific customers. It completely depends on our requirements.
Product price overriding is mostly used for changing some extra amount or giving some extra discount to the customer.
To override the price of the product, we need to follow the following steps.
Let’s say, we want 10% less price than the actual price of the product for all logged-in customers.
First of all, we need to register a new hook named ‘actionProductPriceCalculation’
Note: This hook is available since PrestaShop version 8.1
We use this hook to perform the custom calculation as per our requirements.
Now we define the definition of hook functionality as follows:
public function hookActionProductPriceCalculation($params)
{
// Create your logic here
// return the new price value after custom calculation
$oldPrice = $params['price'];
$newPrice = $oldPrice;
if ($this->context->customer->id) {
$newPrice = $oldPrice - ($oldPrice * (10 / 100));
}
$params['price'] = $newPrice;
}
By applying the above code, we will get the result as follows:
For visitor product price is $29.00 i.e. actual price of the product.

For logged-in customers, the product price is $26.10

That’s all about this blog.
If any issues or doubts in the above step, please feel free to let us know in the comment section.
We would be happy to help.
You can also learn How to Override Symfony Grid Listing in PrestaShop.
You can also explore our PrestaShop Development Services and a large range of quality PrestaShop Modules

Be the first to comment.