Home › Forums › Stripe Payments Plugin › Form defaults / parameters
- This topic has 4 replies, 4 voices, and was last updated 3 years, 7 months ago by canerk.
-
AuthorPosts
-
December 8, 2020 at 2:17 pm #3451[email protected]Participant
Hi guys,
I have already read that it is currently not possible to pre-populate fields with custom or default values in the payment form … which is what is most needed on our end to have a more seamless business logic though. Especially predefine name & email, but also eg. a suggested donation value.
It seems though like there are plans for that? Do you guys have any roadmap? I guess all that could even be a form-defaults action hook for setting default values (which could be safer than just via get params).
Thanks!
December 9, 2020 at 12:22 am #3453AdminKeymasterWe should be able to add filter hooks for this. I will look into this.
December 10, 2020 at 6:06 pm #3455alexanderfoxcParticipantHi.
You can change customer name and donation amount by hooking to
asp-button-output-data-ready
filter.Here’s quick example how to change customer name: https://github.com/Arsenal21/stripe-payments-enhancements/blob/master/asp-prefill-customer-name-and-email/asp-prefill-customer-name-and-email.php
You can change donation amount like this:
$data['item_price'] = 10000; //amount should be in cents
December 11, 2020 at 1:35 pm #3462[email protected]ParticipantExcellent, Alexander – this is basically exactly what I was looking for. Cheers guys!
February 11, 2021 at 10:09 pm #3619canerkParticipantHey alexanderfoxc,
I have a question regarding prefilling the user data using the GET method. Before the payment, I make the user fill out a form with email, phone and name info. On the payment screen, I don’t want them to reenter their name and email. So I want to send the name and email info like “site.com/payment-screen?name=John&[email protected]”
I added a few lines of code to the code you shared earlier to prefill the name and email with the GET data.
// Get the URL parameters assign variables if (isset($_GET['NAME'])) { $s_name = $_GET['NAME']; } else { $s_name = "failed to get post parameter"; } if (isset($_GET['EMAIL'])) { $s_email = $_GET['EMAIL']; } else { $s_email = "failed to get post parameter"; }
and changed the code you shared to:
public function handle_data_ready( $data ) { $data['customer_email'] = $s_email; $data['customer_name'] = $s_name; return $data; }
But it’s not working. I didn’t have high hopes anyways with my little knowledge of PHP. But I was wondering if you had a solution for this.
My next solution might be to try to auto-register the user after filling out the form so the name and email get filled from user info.
Thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.