function woocommerce_apply_giftcard($giftcard_code)
{
    global $wpdb;
    if (!empty($_POST['giftcard_code'])) {
        $giftcard_number = sanitize_text_field($_POST['giftcard_code']);
        if (!isset(WC()->session->giftcard_post)) {
            $giftcard_id = wpr_get_giftcard_by_code($giftcard_number);
            if ($giftcard_id) {
                $current_date = date("Y-m-d");
                $cardExperation = wpr_get_giftcard_expiration($giftcard_id);
                if (strtotime($current_date) <= strtotime($cardExperation) || strtotime($cardExperation) == '') {
                    if (wpr_get_giftcard_balance($giftcard_id) > 0) {
                        WC()->session->giftcard_post = $giftcard_id;
                        wc_add_notice(__('Gift card applied successfully.', 'rpgiftcards'), 'success');
                    } else {
                        wc_add_notice(__('Gift Card does not have a balance!', 'rpgiftcards'), 'error');
                    }
                } else {
                    wc_add_notice(__('Gift Card has expired!', 'rpgiftcards'), 'error');
                    // Giftcard Entered has expired
                }
            } else {
                wc_add_notice(__('Gift Card does not exist!', 'rpgiftcards'), 'error');
                // Giftcard Entered does not exist
            }
        } else {
            wc_add_notice(__('Gift Card already in the cart!', 'rpgiftcards'), 'error');
            //  You already have a gift card in the cart
        }
        wc_print_notices();
    }
}
    public function sendGiftcardEmail($giftCard)
    {
        $expiry_date = wpr_get_giftcard_expiration($giftCard);
        $date_format = get_option('date_format');
        ob_start();
        ?>

		<div class="message">


			<?php 
        _e('Dear', 'rpgiftcards');
        ?>
 <?php 
        echo wpr_get_giftcard_to($giftCard);
        ?>
,<br /><br />
				
			<?php 
        echo wpr_get_giftcard_from($giftCard);
        ?>
 <?php 
        _e('has selected a', 'rpgiftcards');
        ?>
 <strong><a href="<?php 
        bloginfo('url');
        ?>
"><?php 
        bloginfo('name');
        ?>
</a></strong> <?php 
        _e('Gift Card for you! This card can be used for online purchases at', 'rpgiftcards');
        ?>
 <?php 
        bloginfo('name');
        ?>
. <br />

			<h4><?php 
        _e('Gift Card Amount', 'rpgiftcards');
        ?>
: <?php 
        echo woocommerce_price(wpr_get_giftcard_balance($giftCard));
        ?>
</h4>
			<h4><?php 
        _e('Gift Card Number', 'rpgiftcards');
        ?>
: <?php 
        echo get_the_title($giftCard);
        ?>
</h4>

			<?php 
        if ($expiry_date != "") {
            echo __('Expiration Date', 'rpgiftcards') . ': ' . date_i18n(get_option('date_format'), strtotime($expiry_date));
        }
        ?>
		</div>

		<div style="padding-top: 10px; padding-bottom: 10px; border-top: 1px solid #ccc;">
			<?php 
        echo wpr_get_giftcard_note($giftCard);
        ?>
		</div>

		<div style="padding-top: 10px; border-top: 1px solid #ccc;">
			<?php 
        _e('Using your Gift Card is easy', 'rpgiftcards');
        ?>
:

			<ol>
				<li><?php 
        _e('Shop at', 'rpgiftcards');
        ?>
 <?php 
        bloginfo('name');
        ?>
</li>
				<li><?php 
        _e('Select "Pay with a Gift Card" during checkout.', 'rpgiftcards');
        ?>
</li>
				<li><?php 
        _e('Enter your card number.', 'rpgiftcards');
        ?>
</li>
			</ol>
		</div>

		<?php 
        $return = ob_get_clean();
        return apply_filters('rpgc_email_content_return', $return, $giftCard);
    }