public function createCard($giftInformation) { global $wpdb; if (isset($giftInformation['rpgc_description'])) { $giftCard['description'] = woocommerce_clean($giftInformation['rpgc_description']); } if (isset($giftInformation['rpgc_to'])) { $giftCard['to'] = woocommerce_clean($giftInformation['rpgc_to']); } if (isset($giftInformation['rpgc_email_to'])) { $giftCard['toEmail'] = woocommerce_clean($giftInformation['rpgc_email_to']); } if (isset($giftInformation['rpgc_from'])) { $giftCard['from'] = woocommerce_clean($giftInformation['rpgc_from']); } if (isset($giftInformation['rpgc_email_from'])) { $giftCard['fromEmail'] = woocommerce_clean($giftInformation['rpgc_email_from']); } if (isset($giftInformation['rpgc_amount'])) { $giftCard['amount'] = woocommerce_clean($giftInformation['rpgc_amount']); if (!isset($giftInformation['rpgc_balance'])) { $giftCard['balance'] = woocommerce_clean($giftInformation['rpgc_amount']); $giftCard['sendTheEmail'] = 1; } } if (isset($giftInformation['rpgc_balance'])) { $giftCard['balance'] = woocommerce_clean($giftInformation['rpgc_balance']); } if (isset($giftInformation['rpgc_note'])) { $giftCard['note'] = woocommerce_clean($giftInformation['rpgc_note']); } if (isset($giftInformation['rpgc_expiry_date'])) { $giftCard['expiry_date'] = woocommerce_clean($giftInformation['rpgc_expiry_date']); } else { $giftCard['expiry_date'] = ''; } if ($_POST['post_title'] == '' || isset($giftInformation['rpgc_regen_number'])) { if ($giftInformation['rpgc_regen_number'] == 'yes' || $_POST['post_title'] == '') { $newNumber = apply_filters('rpgc_regen_number', $this->generateNumber()); $wpdb->update($wpdb->posts, array('post_title' => $newNumber), array('ID' => $_POST['ID'])); $wpdb->update($wpdb->posts, array('post_name' => $newNumber), array('ID' => $_POST['ID'])); } } if ($giftCard['sendTheEmail'] == 1 && $giftCard['balance'] != 0 || isset($giftInformation['rpgc_resend_email'])) { $email = new WPR_Giftcard_Email(); $post = get_post($_POST['ID']); $email->sendEmail($post); } update_post_meta($_POST['ID'], '_wpr_giftcard', $giftCard); }
public function sendEmail($post) { $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = apply_filters('woocommerce_email_subject_gift_card', sprintf('[%s] %s', $blogname, __('Gift Card Information', 'rpgiftcards')), $post->post_title); $sendEmail = get_bloginfo('admin_email'); $headers = array('Content-Type: text/html; charset=UTF-8'); ob_start(); $mailer = WC()->mailer(); $email = new WPR_Giftcard_Email(); echo '<style >'; wc_get_template('emails/email-styles.php'); echo '</style>'; $email_heading = __('New gift card from ', 'rpgiftcards') . $blogname; $email_heading = apply_filters('rpgc_emailSubject', $email_heading); $toEmail = wpr_get_giftcard_to_email($post->ID); $theMessage = $email->sendGiftcardEmail($post->ID); $theMessage = apply_filters('rpgc_emailContents', $theMessage); echo $mailer->wrap_message($email_heading, $theMessage); $message = ob_get_clean(); $attachment = ''; $email = new WC_Email(); $email->send($toEmail, $subject, $message, $headers, $attachment); }
/** * Save the meta when the post is saved. * * @param int $post_id The ID of the post being saved. */ public function save($post_id) { global $post, $wpdb; /* * We need to verify this came from the our screen and with proper authorization, * because save_post can be triggered at other times. */ // Check if our nonce is set. if (!isset($_POST['woocommerce_giftcard_nonce'])) { return $post_id; } $nonce = $_POST['woocommerce_giftcard_nonce']; // Verify that the nonce is valid. if (!wp_verify_nonce($nonce, 'woocommerce_save_data')) { return $post_id; } // If this is an autosave, our form has not been submitted, // so we don't want to do anything. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check the user's permissions. if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } /* OK, its safe for us to save the data now. */ $description = ''; $to = ''; $toEmail = ''; $from = ''; $fromEmail = ''; $sendto_from = ''; $sendautomaticly = ''; $amount = ''; $balance = ''; $note = ''; $expiry_date = ''; $sendTheEmail = 0; //var_dump( $post ); //die(); // Ensure gift card code is correctly formatted //$wpdb->update( $wpdb->posts, array( 'post_title' => $post->post_title ), array( 'ID' => $post_id ) ); /*if ( wpr_get_giftcard_by_code( $post->post_title ) ) { $newNumber = apply_filters( 'rpgc_regen_number', rpgc_generate_number()); $wpdb->update( $wpdb->posts, array( 'post_title' => $newNumber ), array( 'ID' => $post_id ) ); $wpdb->update( $wpdb->posts, array( 'post_name' => $newNumber ), array( 'ID' => $post_id ) ); }*/ if (isset($_POST['rpgc_description'])) { $description = woocommerce_clean($_POST['rpgc_description']); update_post_meta($post_id, 'rpgc_description', $description); } if (isset($_POST['rpgc_to'])) { $to = woocommerce_clean($_POST['rpgc_to']); update_post_meta($post_id, 'rpgc_to', $to); } if (isset($_POST['rpgc_email_to'])) { $toEmail = woocommerce_clean($_POST['rpgc_email_to']); update_post_meta($post_id, 'rpgc_email_to', $toEmail); } if (isset($_POST['rpgc_from'])) { $from = woocommerce_clean($_POST['rpgc_from']); update_post_meta($post_id, 'rpgc_from', $from); } if (isset($_POST['rpgc_email_from'])) { $fromEmail = woocommerce_clean($_POST['rpgc_email_from']); update_post_meta($post_id, 'rpgc_email_from', $fromEmail); } if (isset($_POST['rpgc_amount'])) { $amount = woocommerce_clean($_POST['rpgc_amount']); update_post_meta($post_id, 'rpgc_amount', $amount); if (!isset($_POST['rpgc_balance'])) { $balance = woocommerce_clean($_POST['rpgc_amount']); update_post_meta($post_id, 'rpgc_balance', $balance); $sendTheEmail = 1; } } if (isset($_POST['rpgc_balance'])) { $balance = woocommerce_clean($_POST['rpgc_balance']); update_post_meta($post_id, 'rpgc_balance', $balance); } if (isset($_POST['rpgc_note'])) { $note = woocommerce_clean($_POST['rpgc_note']); update_post_meta($post_id, 'rpgc_note', $note); } if (isset($_POST['rpgc_expiry_date'])) { $expiry_date = woocommerce_clean($_POST['rpgc_expiry_date']); update_post_meta($post_id, 'rpgc_expiry_date', $expiry_date); } else { $expiry_date = ''; } if (isset($_POST['rpgc_regen_number'])) { if ($_POST['rpgc_regen_number'] == 'yes') { $newNumber = apply_filters('rpgc_regen_number', rpgc_generate_number()); $wpdb->update($wpdb->posts, array('post_title' => $newNumber), array('ID' => $post_id)); $wpdb->update($wpdb->posts, array('post_name' => $newNumber), array('ID' => $post_id)); } } if ($sendTheEmail == 1 && $balance != 0 || isset($_POST['rpgc_resend_email'])) { $email = new WPR_Giftcard_Email(); $post = get_post($post_id); $email->sendEmail($post); update_post_meta($post_id, 'rpgc_email_sent', "true"); } /* Deprecated - same hook name as in the meta */ do_action('woocommerce_rpgc_options'); do_action('woocommerce_rpgc_options_save'); }