Skip to content

Instantly share code, notes, and snippets.

@New0
Created November 29, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save New0/3c80baa0e0ebed7db40667e4bdcbea2e to your computer and use it in GitHub Desktop.
Save New0/3c80baa0e0ebed7db40667e4bdcbea2e to your computer and use it in GitHub Desktop.
Custom WordPress plugin used as an extension of Direct Stripe Plugin
<?php
/*
* Plugin Name: DS custom code
* Author: Nicolas Figueira
* Description: Direct Stripe custom actions and filters
* Plugin URI: https://gist.github.com/New0/d72217de1e60871cf938715c2fd03b61
*
* This code is an add-on of Direct Stripe WordPress plugin
*/
//Add the email receipt parameter to the Stripe user after a successfull charge
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment