There is an action hook processed just before any successful transaction that can be used to add (for example) a receipt_email to the current charge :
Tha action is ‘direct_stripe_before_success_redirection’
Its parameters are :
- Charge ID – ID of the Charge that was just created with Stripe API
- Post ID – ID of the log created for the current transaction
- Button ID – ID set with the shortcode parameter “button_id”
- User ID – ID of the Stripe User
Here we go :
function my_direct_stripe_action($chargeID, $post_id, $button_id, $user_id) { // Add the action for a precise button setting a button_id if( $button_id === '1') { // Retrieve the user to identify its email address $user = get_user_by( 'ID', $user_id ); $email_address = $user->user_email; //Retrieve Stripe Charge and update it $ch = \Stripe\Charge::retrieve($chargeID); $ch->receipt_email = $email_address; $ch->save(); } } // Pass the function 'my_direct_stripe_action' through the action with priority 10 and 4 parameters add_action( 'direct_stripe_before_success_redirection', 'my_direct_stripe_action', 10, 4 );
If you are in a testing environment, stripe don’t send the receipt but you can check in the logs that the charge was updated.
Hello,
I’ve posted a comment on this topic elsewhere but I can’t find my way back to it.
can you lead me to it ?
I also know you responded to my comment with a whole solution and you’re of great help !
Thank you very much !
Kevin
Hello Kevin,
You will find your comment at https://newo.me/direct-stripe-actions-and-filters-hooks/#comments
Best wishes,
Nico