Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #2294193
Help to program discounts
Closed

Comments

  • Rafa Carvalhido started the conversation

    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.

  •  767
    Janilyn replied

    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

  • Rafa Carvalhido replied

    Hello! I´m still waiting on a reply. Is there anyone who can help me?

  •  1,222
    Dustin replied

    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

  • Rafa Carvalhido replied

    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?

  • Rafa Carvalhido replied

    Hello, my problem is not solved yet. Can you help me, please?