Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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 );
- }
- }
Add Comment
Please, Sign In to add comment