Skip to content

Instantly share code, notes, and snippets.

@New0
Created March 11, 2018 20:43
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/c7d0ebe2c75f6f371aa6e727129b7446 to your computer and use it in GitHub Desktop.
Save New0/c7d0ebe2c75f6f371aa6e727129b7446 to your computer and use it in GitHub Desktop.
Custom plugin to send custom data from a text area after transaction success with Direct Stripe
<?php
/*
* Plugin Name: Direct Stripe custom hooks
* Author: Nicolas Figueira
*
*/
//Add a textarea before the button
add_action( 'direct_stripe_before_button', function() {
?>
<div class="sms-hook">
<label><?php _e('The SMS content', 'textdomain'); ?></label>
<textarea class="sms-content"></textarea>
</div>
<?php
});
//GET transient and use sms data on transaction success
add_action( 'direct_stripe_before_success_redirection', function() {
$sms = get_transient('sms_value');
wp_mail( 'email_adress', 'subject', $sms);
});
//Add jQuery using wp_footer to get the data from the textarea
add_action('wp_footer', function() {
?><script type="text/javascript">
jQuery(".direct-stripe-button").on("click", function() {
var sms = jQuery(".sms-content").val();
var ajaxurl = <?php admin_url( 'admin-ajax.php' ); ?>
jQuery.post(
ajaxurl,
{
'action': 'ds_set_sms',
'sms': sms
}
);
});
</script>
<?php
});
//SET Transient
add_action( 'wp_ajax_ds_set_sms', 'ds_set_sms' );
add_action( 'wp_ajax_nopriv_ds_set_sms', 'ds_set_sms' );
function ds_set_sms() {
$sms = isset($_POST['sms']) ? $_POST['sms'] : '';
if( isset( $sms ) ) {
set_transient("sms_value", $sms );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment