Hello, I´m a developer and my client has bought your plugin. He hired me to apply a complex discount formula to the site prices based on the user role and the product category.
I need to know how can I programmatically apply a discount to a product on its final price, after all components are added. So far, what I did is discounting the main price and each component.
This would be fine if the discount was something easy such as 10%. But it´s something like:
$price = ($base_price / 0.105) - 5;
Where this 5 above is actually currency units. For example, using the above formula for a product that costs $100 and has 3 components for $10 each, the price should be:
$price = (130 / 1.05) -5 = 118.81
But it´s actually doing:
$price = (100 / 1.05) - 5 = 90.23 +
(10 / 1.05) - 5 = 4.52 (x3 for each component)
Which brings to a total of 90.23 + 4.52 + 4.52 + 4.52 = 103.79
From 118.81 to 103.79.
I´ve attached the part of my code that shows all hooks I´m using to add my discount. Let me know if you need anymore.
Thank you for contacting WPClever Support Forum. We’ve received your ticket and assigned one of our developers to help you with that. He’ll be looking into your request and responding as soon as finding a solution. Please stay in touch as he might need you to provide further information.
Kindly note that support might be a bit slower than normal in the weekends.
In our plugin, we set the price for the composite product or components products in the function "wooco_get_cart_contents". Please find this function and change the final price as you want.
Hi Frankie! Thanks for your response. The function you mentioned should only change the price in the cart, right? The thing is the price is showing discounted wrong also on product single pages (did you see the print I sent showing the hooks I´m addressing?).
How can I find out on product page if the product is composite? Once I find out it is composite, how do I discount only the final price and not the base plus each component?
Hello, I´m a developer and my client has bought your plugin. He hired me to apply a complex discount formula to the site prices based on the user role and the product category.
I need to know how can I programmatically apply a discount to a product on its final price, after all components are added. So far, what I did is discounting the main price and each component.
This would be fine if the discount was something easy such as 10%. But it´s something like:
$price = ($base_price / 0.105) - 5;
Where this 5 above is actually currency units. For example, using the above formula for a product that costs $100 and has 3 components for $10 each, the price should be:
$price = (130 / 1.05) -5 = 118.81
But it´s actually doing:
$price = (100 / 1.05) - 5 = 90.23 +
(10 / 1.05) - 5 = 4.52 (x3 for each component)
Which brings to a total of 90.23 + 4.52 + 4.52 + 4.52 = 103.79
From 118.81 to 103.79.
I´ve attached the part of my code that shows all hooks I´m using to add my discount. Let me know if you need anymore.
Hi,
Thank you for contacting WPClever Support Forum. We’ve received your ticket and assigned one of our developers to help you with that. He’ll be looking into your request and responding as soon as finding a solution. Please stay in touch as he might need you to provide further information.
Kindly note that support might be a bit slower than normal in the weekends.
Thanks for your understanding.
Best regards.
Janilyn T. - WPClever Support Agent
Hello! I´m still waiting on a reply. Is there anyone who can help me?
Hi Rafa,
Sorry for the late reply!
In our plugin, we set the price for the composite product or components products in the function "wooco_get_cart_contents". Please find this function and change the final price as you want.
Best regards,
Dustin
Hi Frankie! Thanks for your response. The function you mentioned should only change the price in the cart, right? The thing is the price is showing discounted wrong also on product single pages (did you see the print I sent showing the hooks I´m addressing?).
How can I find out on product page if the product is composite? Once I find out it is composite, how do I discount only the final price and not the base plus each component?
Hello, my problem is not solved yet. Can you help me, please?