Guest User

Untitled

a guest
Mar 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2. /*
  3. * Plugin Name: Direct Stripe custom hooks
  4. * Author: Nicolas Figueira
  5. *
  6. */
  7.  
  8. //Add a textarea before the button
  9. add_action( 'direct_stripe_before_button', function() {
  10. ?>
  11. <div class="sms-hook">
  12. <label><?php _e('The SMS content', 'textdomain'); ?></label>
  13. <textarea class="sms-content"></textarea>
  14. </div>
  15. <?php
  16. });
  17.  
  18. //GET transient and use sms data on transaction success
  19. add_action( 'direct_stripe_before_success_redirection', function() {
  20.  
  21. $sms = get_transient('sms_value');
  22. wp_mail( 'email_adress', 'subject', $sms);
  23.  
  24.  
  25. });
  26.  
  27. //Add jQuery using wp_footer to get the data from the textarea
  28. add_action('wp_footer', function() {
  29. ?><script type="text/javascript">
  30. jQuery(".direct-stripe-button").on("click", function() {
  31. var sms = jQuery(".sms-content").val();
  32. var ajaxurl = <?php admin_url( 'admin-ajax.php' ); ?>
  33. jQuery.post(
  34. ajaxurl,
  35. {
  36. 'action': 'ds_set_sms',
  37. 'sms': sms
  38. }
  39. );
  40. });
  41. </script>
  42. <?php
  43. });
  44.  
  45.  
  46. //SET Transient
  47. add_action( 'wp_ajax_ds_set_sms', 'ds_set_sms' );
  48. add_action( 'wp_ajax_nopriv_ds_set_sms', 'ds_set_sms' );
  49.  
  50. function ds_set_sms() {
  51. $sms = isset($_POST['sms']) ? $_POST['sms'] : '';
  52. if( isset( $sms ) ) {
  53. set_transient("sms_value", $sms );
  54. }
  55. }
Add Comment
Please, Sign In to add comment