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