Support » Plugin: WooCommerce » Woocommerce dynamic variation prices

  • Resolved bmontgomery

    (@bmontgomery)


    Hello,

    I have a question that I’ve been struggling with for hours, I’m sure you’ll be able to help me.

    Here’s the context :
    I developped a website where people can order variable products. But these products have prices that are variable, depending on different parameters that I won’t explain here.
    I was able to develop some functions that deal with all this stuff, and everything workds fine.

    However, when the user is on the product page, when he chooses different options, the price remains the same – until now I had decided to hide the price and it was only showed to the customer after adding the product into the cart. Because my dynamic price calculation was happening on the add to cart event.

    Now I’d like to actually show the user what the price will be BEFORE he adds the item to the cart. But in my case, I setup variation prices to a fixes value, always the same.

    I was able to locate the jquery function that is triggered when the user chooses the options, and I can see that there’s an ajax call that updates a variable called “variation”. So I’d like to be able to act during this call so that the “variation” variable gets returned with the correct price (and not the one that I put in the beginning).

    I tried to add a filter on woocommerce_variation_prices :
    I was able to change the value of $transient_cached_prices_array_price_hash and put there the correct price. However my page still displays the former prices and not the ones that I updated.

    Could you please help me ?
    What am I doing wrong ?
    Is there another hook that I could use ?

    Thanks for your help, I’m really stuck…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Stef

    (@serafinnyc)

    Maybe I’m not understanding you correctly but you can set separate pricing on variable products for certain by default and the main price would state 10 – 30 for example.

    Did I misunderstand your request?

    Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hi @bmontgomery

    I developped a website where people can order variable products. But these products have prices that are variable, depending on different parameters that I won’t explain here.

    To confirm – the price of each variation isn’t the same for each customer, is that correct? Is that where the dynamic price comes in?

    Now I’d like to actually show the user what the price will be BEFORE he adds the item to the cart. But in my case, I setup variation prices to a fixes value, always the same.

    This is a fairly complex development topic for doing this yourself. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:

    1. WooCommerce Slack Community: https://woocommerce.com/community-slack/
    2. Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    If you’re looking for a ready-made solution, there are extensions and plugins available. I’m not familiar with any third-party ones but I know of the Dynamic Pricing extension from WooCommerce.com

    Thanks,

    Hello and thanks for your answers.

    @stef I’m not sure you understood my issue. It’s actually a bit complex and I was not able to explain it easily – and I’m not native english 🙂

    I was about to succeed, I had found some woocommerce filters that are triggered and that let me make some changes on the prices but now I have another issue.

    @dougaitken Yes the price is not the samùe for each customer.
    To be more specific, one of the criteria is the number of days that the client will be booking the product. I installed a plugin that deals with booking dates so it’s working great. I have the number of days and I made some back office tables to add the prices depending on the option (attribute) and number of days.

    As I said, it’s already working with no bug.
    The only thing is that I’d like to dynamically display the information.

    One thing I forgot to mention (and I realized while i was developping) is that I use only one variation in each product, with generic values. Let me explain :

    First I was using Woocommerce as I always did, and I click on the button to generate all the possible variations for each product. But it lead to a huge number of variations. That’s why I decided to follow the advice of another developer and I just added one variation chose no value at all.

    For example, for one product I have these attributes : More ram / More memory
    And that’s all. I just choose the default behavior which is for example : More Ram : no / More memory : no

    When the user gets on the product page, the default product is with no ram and no memory. Then he can choose to add more ram and/or more memory.

    This is a simple example, I had thousands of possibilities at first and it was not handled correctly.

    Anyway : My issue now is when I click to make a change on the options, nothing happens… the function that was supposed to be called when an option is chosen is not triggered anymore and it’s a big problem.

    To be more specific, in add-to-cart-variation.js, there’s a function VariationForm.prototype.onChange which is not triggered, even if I change the options on the product page.

    I’m going to visit the slack community and see if someone can help me…
    Very complex indeed.

    Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hey @bmontgomery

    I’m going to visit the slack community and see if someone can help me…
    Very complex indeed.

    Sounds good, this is very complex so possibly hiring a developer would make sense for this.

    Thanks,

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.