PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dynamically Populate Price in Product Field

  1. Background:
    I am building a quote engine on my website. I am trying to use GF to quote my customers. Product Prices are stored in a database and are updated automatically based on an external XML feed.

    My question is two fold:
    1. I wish to use Product Fields (single product), but somehow dynamically populate the "Base Price"
    2. I wish to rename the "Price:" and "Quantity:" labels in the Product Field.

    Is this possible? If so, how?

    Many thanks

    Posted 12 years ago on Saturday August 18, 2012 | Permalink
  2. To change the price, you can check the "Allow field to be populated dynamically" box on the advanced tab for your product. The screen will look like this at that point: http://minus.com/lY5WUTPLBsp8A

    Set those three parameters. Then use one of these three methods to dynamically populate the field. http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population

    For pulling the information from the database or external XML feed, you probably want to use the last example, explaining how to do it with a hook. http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population#Hooks

    For changing Price and Quantity labels, you can use these filters:

    http://www.gravityhelp.com/documentation/page/Gform_product_price
    http://www.gravityhelp.com/documentation/page/Gform_product_quantity

    Posted 12 years ago on Saturday August 18, 2012 | Permalink
  3. That's exactly what I wanted! Thank you.

    Before you close this thread, could you kindly explain what ", 10, 2" means in

    [php]
    add_filter("gform_product_quantity_9", "set_quantity_label", 10, 2);

    also, and sorry to be a pain, but if some items are being sold by weight, and some items are being sold by qty, (hence the reason why I want to rename the labels), how do I change the labels for specific pricing fields?

    // Change quantity sublabel to Weight
    add_filter("gform_product_quantity_9", "set_quantity_label", 10, 2);
    function set_quantity_label($sublabel, $form_id){
        return "Weight";
    }

    The above changes label for ALL quantity fields but not specific ones. I have tried

    [php]
    gform_product_quantity_9_2

    to amend the item with field id 2 to no avail.

    Posted 12 years ago on Saturday August 18, 2012 | Permalink
  4. The 10, 2 is priority (10) and number of arguments accepted (2). See here: http://codex.wordpress.org/Function_Reference/add_filter

    I will check with the developers on changing just some of the labels in a single form.

    Posted 12 years ago on Sunday August 19, 2012 | Permalink
  5. Hi Chris,

    Any luck?

    Posted 12 years ago on Monday August 27, 2012 | Permalink