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.

Accessing product prices in gform_pre_submission

  1. anniengo
    Member

    Hi...

    I need to add up the prices for a subset of products. My hook to gform_pre_submission is able to concatenate strings of selected options, but I can't for the life of me get to the product prices. It looks like all the field object pricing properties can be manipulated before displaying the form, but how can I add prices based on the user selections?

    Thanks...

    Posted 12 years ago on Thursday December 8, 2011 | Permalink
  2. anniengo
    Member

    Well I found one way to do it... The product name itself includes the price (eg. "Sandwich | 7.50"), and I had stripped that off to make it look "cleaner". So I changed it to strip off the price:

    $prod = $_POST["input_5"];
    $prodE = explode("|", $prod,2); // breaks apart the product into 2 parts, separated by "|"
    $price = $prodE[1]; // the 2nd part is the price

    Of course I'd appreciate learning a simpler way if anyone knows how :)

    Posted 12 years ago on Thursday December 8, 2011 | Permalink
  3. Hi, anniengo,

    I may not be understanding your request, but the pricing information is all available in $_POST for you to grab out. You mentioned the price was included with the product name, but that is the price for the OPTION field associated to a product.

    For each of the product fields there will be 3 (2 if using a separate quantity field) pieces of information in $POST for a product field. For instance, if my field is id 10, then input_10_1 is the product name, input_10_2 is the base price, and input_10_3 is the quantity (if your product field includes the quantity field with it). So you would need to get the price of the product, price of the option (which is what you are doing in your example) and multiply that times the quantity. If using a separate quantity field then you would need to grab out the qty from the separate field associated to your product field.

    If you need the amount of all products on the page, then using the Total field is the best thing to use, but I understood your question to be in regards to only getting the prices for some of the products.

    Let me know if you have any questions about this.

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink
  4. anniengo
    Member

    Thanks for the response Dana! So do I understand that there's not a more direct way to get the option price?

    The form has 5 pages, one for each weekday. I need the total for Mondays (page 1), Tuesdays (page 2), etc. I was thinking the "total" field was a cumulative total. Is there a way to get the total for each page?

    Posted 12 years ago on Saturday December 17, 2011 | Permalink
  5. Yes, the total price is cumulative across all pages. Unfortunately, there isn't any easy way to get the total for each page. Using the $_POST information for the products/options is the only way to get a total per page.

    Posted 12 years ago on Tuesday December 20, 2011 | Permalink

This topic has been resolved and has been closed to new replies.