<?php

if (!defined('ABSPATH')) exit;  // Exit if accessed directly

// Add Voucher Shortcode
function wpgv_giftitems_shortcode($atts = array())
{
    $shortcode_attr = shortcode_atts(array(
        'item_id' => 0,
        'item_cat_id' => 0
    ), $atts);

    global $wp, $wpdb;
    $html = '';
    $find = array('http://', 'https://');
    $replace = '';
    $siteURL = str_replace($find, $replace, get_site_url());
    $setting_table  = $wpdb->prefix . 'giftvouchers_setting';
    $voucher_table  = $wpdb->prefix . 'giftvouchers_list';
    $invoice_setting_table = $wpdb->prefix . 'giftvouchers_invoice_settings';

    wp_enqueue_style('wpgv-item-style');
    wp_enqueue_script('wpgv-jquery-validate');
    wp_enqueue_script('wpgv-item-script');
    wp_enqueue_script('wpgv-stripe-js');
    wp_enqueue_script('wpgv-paypal-js');
    wp_enqueue_script('wpgv-klarna');  // Add Klarna widget handler
    wp_enqueue_style('wpgv-bootstrap-datetimepicker-css');
    wp_enqueue_script('wpgv-bootstrap-datetimepicker-js');

    $setting_options = $wpdb->get_row("SELECT * FROM $setting_table WHERE id = 1");
    $invoice_options = $wpdb->get_row("SELECT * FROM $invoice_setting_table WHERE id = 1");
    $nonce = wp_create_nonce('wpgv_giftitems_form_verify');
    $wpgv_custom_css = get_option('wpgv_custom_css') ? stripslashes(trim(get_option('wpgv_custom_css'))) : '';

    $wpgv_multisafepay = get_option('wpgv_multisafepay') ? get_option('wpgv_multisafepay') : 0;
    $wpgv_paypal_alternative_text = get_option('wpgv_paypal_alternative_text') ? get_option('wpgv_paypal_alternative_text') : 'PayPal';
    $wpgv_stripe_alternative_text = get_option('wpgv_stripe_alternative_text') ? get_option('wpgv_stripe_alternative_text') : 'Stripe';
    $wpgv_multisafepay_alternative_text = get_option('wpgv_multisafepay_alternative_text') ? get_option('wpgv_multisafepay_alternative_text') : 'MultiSafepay';
    $wpgv_klarna = get_option('wpgv_klarna') ? get_option('wpgv_klarna') : 0;
    $wpgv_klarna_display = get_option('wpgv_klarna_display_name') ? get_option('wpgv_klarna_display_name') : __('Klarna', 'gift-voucher');

    $wpgv_paypal_alternative_text = get_option('wpgv_paypal_alternative_text') ? get_option('wpgv_paypal_alternative_text') : 'PayPal';
    $wpgv_stripe_alternative_text = get_option('wpgv_stripe_alternative_text') ? get_option('wpgv_stripe_alternative_text') : 'Stripe';

    $wpgv_buying_for = get_option('wpgv_buying_for') ? get_option('wpgv_buying_for') : 'both';

    $wpgv_additional_charges_text = get_option('wpgv_additional_charges_text_item') ? get_option('wpgv_additional_charges_text_item') : 'Additional Website Charges';
    $wpgv_add_extra_charges = get_option('wpgv_add_extra_charges_item') ? get_option('wpgv_add_extra_charges_item') : 0;
    if ($wpgv_buying_for == 'both') {
        $buying_for_html = '<div class="buying-for flex-field">
                    <label>' . __('Buying For', 'gift-voucher') . '</label>
                    <div class="buying-options">
                        <div class="someone_else selected" data-value="someone_else">
                            <img src="' . WPGIFT__PLUGIN_URL . '/assets/img/giftbox.png">
                            <span>' . __('Someone Else', 'gift-voucher') . '</span>
                        </div>
                        <div class="yourself" data-value="yourself">
                            <img src="' . WPGIFT__PLUGIN_URL . '/assets/img/users.png">
                            <span>' . __('Yourself', 'gift-voucher') . '</span>
                        </div>
                    </div>
                    <input type="hidden" name="buying_for" id="buying_for" value="someone_else">
                </div>
                <div class="wpgv-form-fields" id="wpgv-your_name">
                    <label for="your_name">' . __('Your Name', 'gift-voucher') . '</label>
                    <span class="error">' . __('Your name is required', 'gift-voucher') . '</span>
                    <input type="text" name="your_name" id="your_name" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-recipient_name">
                    <label for="receipt_email">' . __('Recipient Name', 'gift-voucher') . '</label>
                    <span class="error">' . __('Recipient name is required', 'gift-voucher') . '</span>
                    <input type="text" name="recipient_name" id="recipient_name" class="form-field" />
                </div>
                <div class="wpgv-form-fields" id="wpgv-list-view-price">
                    <label for="receipt_email">' . __('Value (Min Voucher Value)*', 'gift-voucher') . '</label>
                    <span class="error">' . __('Recipient price is required', 'gift-voucher') . '</span>
                    <input type="number" name="list_view_price" id="list_view_price" class="form-field" />
                </div>';
    } else {
        if ($wpgv_buying_for == 'someone_else') {
            $buying_for_html = '<input type="hidden" name="buying_for" id="buying_for" value="someone_else">
                <div class="wpgv-form-fields" id="wpgv-your_name">
                    <label for="your_name">' . __('Your Name', 'gift-voucher') . '</label>
                    <span class="error">' . __('Your name is required', 'gift-voucher') . '</span>
                    <input type="text" name="your_name" id="your_name" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-recipient_name">
                    <label for="receipt_email">' . __('Recipient Name', 'gift-voucher') . '</label>
                    <span class="error">' . __('Recipient name is required', 'gift-voucher') . '</span>
                    <input type="text" name="recipient_name" id="recipient_name" class="form-field" />
                </div>
                <div class="wpgv-form-fields" id="wpgv-list-view-price">
                    <label for="receipt_email">' . __('Value (Min Voucher Value)*', 'gift-voucher') . '</label>
                    <span class="error">' . __('Recipient price is required', 'gift-voucher') . '</span>
                    <input type="number" name="list_view_price" id="list_view_price" class="form-field" />
                </div>';
        } else {
            $buying_for_html = '<input type="hidden" name="buying_for" id="buying_for" value="yourself">
                <div class="wpgv-form-fields" id="wpgv-your_name">
                    <label for="your_name">' . __('Your Name', 'gift-voucher') . '</label>
                    <span class="error">' . __('Your name is required', 'gift-voucher') . '</span>
                    <input type="text" name="your_name" id="your_name" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-list-view-price">
                <label for="receipt_email">' . __('Value (Min Voucher Value)*', 'gift-voucher') . '</label>
                <span class="error">' . __('Recipient price is required', 'gift-voucher') . '</span>
                <input type="number" name="list_view_price" id="list_view_price" class="form-field" />
            </div>';
        }
    }

    $wpgv_hide_price = get_option('wpgv_item_hide_price') ? get_option('wpgv_item_hide_price') : 0;
    $wpgv_leftside_notice = (get_option('wpgv_leftside_notice') != '') ? get_option('wpgv_leftside_notice') : __('Cash payment is not possible. The terms and conditions apply.', 'gift-voucher');

    $voucher_value_html = (!$wpgv_hide_price) ? '<div class="voucherValueForm">
                        <label>' . __('Voucher Value', 'gift-voucher') . '</label>
                        <span class="currencySymbol" style="' . (($setting_options->currency_position == 'Left') ? 'left:15px;right:unset;' : 'right:15px;left:unset;') . '"> ' . $setting_options->currency . ' </span>
                        <input style="' . (($setting_options->currency_position == 'Left') ? 'padding-left:30px;padding-right:10px' : 'padding-right:30px;padding-left:10px') . '" type="text" name="voucherValueCard" class="voucherValueCard" readonly>
                    </div>' : '';

    $voucher_bgcolor = $setting_options->voucher_bgcolor;
    $voucher_color = $setting_options->voucher_color;
    // Prepare zebra colors for suggestion list based on voucher border color
    $voucher_brcolor = get_option('wpgv_voucher_border_color') ? get_option('wpgv_voucher_border_color') : '1371ff';
    $voucher_brcolor_hex = ltrim($voucher_brcolor, '#');
    if (strlen($voucher_brcolor_hex) === 3) {
        $voucher_brcolor_hex = $voucher_brcolor_hex[0] . $voucher_brcolor_hex[0]
            . $voucher_brcolor_hex[1] . $voucher_brcolor_hex[1]
            . $voucher_brcolor_hex[2] . $voucher_brcolor_hex[2];
    }
    $r = hexdec(substr($voucher_brcolor_hex, 0, 2));
    $g = hexdec(substr($voucher_brcolor_hex, 2, 2));
    $b = hexdec(substr($voucher_brcolor_hex, 4, 2));
    $li_bg1 = "background-color: rgba($r,$g,$b,0.08);";
    $li_bg2 = "background-color: rgba($r,$g,$b,0.16);";

    // Load quotes (JSON) early so we can decide visibility
    $quotes_raw = get_option('wpgv_quotes', '');
    $quotes = array();
    if (!empty($quotes_raw)) {
        $decoded = json_decode($quotes_raw, true);
        if (is_array($decoded)) {
            $quotes = $decoded;
        }
    }
    $has_quotes = !empty($quotes);
    $custom_loader = $setting_options->custom_loader ? $setting_options->custom_loader : WPGIFT__PLUGIN_URL . '/assets/img/loader.gif';
    $wpgv_termstext = get_option('wpgv_termstext') ? get_option('wpgv_termstext') : 'I hereby accept the terms and conditions, the revocation of the privacy policy and confirm that all information is correct.';

    // number format new
    $shipping_methods = explode('|', $setting_options->shipping_method);
    $shipping_methods_string = '';
    foreach ($shipping_methods as $method) {
        if ($method != '') {
            $shipping_method = explode(':', $method);
            $shipping_methods_string .= '<label data-value="' . trim($shipping_method[0]) . '"><input type="radio" name="shipping_method" value="' . trim(stripslashes($shipping_method[1])) . '" class="radio-field"> ' . trim(stripslashes($shipping_method[1])) . '</label>';
        }
    }

    $wpgv_hide_expiry = get_option('wpgv_hide_expiry') ? get_option('wpgv_hide_expiry') : 'yes';
    $wpgv_expiry_date_format = get_option('wpgv_expiry_date_format') ? get_option('wpgv_expiry_date_format') : 'd.m.Y';

    if ($wpgv_hide_expiry == 'no') {
        $expiryCard = __('No Expiration', 'gift-voucher');
    } else {
        $expiryCard = ($setting_options->voucher_expiry_type == 'days') ? date_i18n($wpgv_expiry_date_format, strtotime('+' . $setting_options->voucher_expiry . ' days', time())) . PHP_EOL : $setting_options->voucher_expiry;
    }

    $chooseStyle = '';
    if ($setting_options->is_style_choose_enable) {
        $voucher_styles = json_decode($setting_options->voucher_style);
        $chooseStyle = '<select name="chooseStyle" id="chooseStyle" class="form-field">';
        foreach ($voucher_styles as $key => $value) {
            $chooseStyle .= '<option value="' . $value . '">' . __('Style', 'gift-voucher') . ' ' . ($value + 1) . '</option>';
        }
        $chooseStyle .= '</select>';
    }

    $paymenyGateway = __('Payment Method');
    if ($setting_options->paypal || $setting_options->sofort || $setting_options->stripe || $setting_options->per_invoice || $wpgv_multisafepay || $setting_options->mollie || $wpgv_klarna) {
        $paymenyGateway = '<select name="payemnt_gateway" id="payemnt_gateway" class="form-field">';
        $paymenyGateway .= $setting_options->stripe ? '<option value="Stripe">' . $wpgv_stripe_alternative_text . '</option>' : '';
        $paymenyGateway .= $setting_options->paypal ? '<option value="Paypal">' . $wpgv_paypal_alternative_text . '</option>' : '';
        $paymenyGateway .= $wpgv_multisafepay ? '<option value="MultiSafepay">' . $wpgv_multisafepay_alternative_text . '</option>' : '';
        $paymenyGateway .= ($wpgv_klarna == 1) ? '<option value="Klarna">' . esc_html($wpgv_klarna_display) . '</option>' : '';
        $paymenyGateway .= $setting_options->mollie ? '<option value="mollie">' . __('Mollie', 'gift-voucher') . '</option>' : '';
        $paymenyGateway .= $setting_options->sofort ? '<option value="Sofort">' . __('Sofort', 'gift-voucher') . '</option>' : '';
        $paymenyGateway .= $setting_options->per_invoice ? '<option value="Per Invoice">' . __('Per Invoice', 'gift-voucher') . '</option>' : '';
        $paymenyGateway .= '</select>';
    }
    $paymentCount = $setting_options->paypal + $setting_options->sofort + $setting_options->stripe + $wpgv_multisafepay + $setting_options->per_invoice;

    $html .= '<style type="text/css">
        .wpgv_preview-box .cardDiv,
        .wpgv-item .wpgv-buy button,
        .buying-options div.selected,
        .shipping-options div.selected,
        .wpgv-buttons .next-button,
        .wpgv-buttons #paynowbtn {
            background-color: #' . $voucher_bgcolor . '!important;
        }
        .wpgv_preview-box .cardDiv .voucherBottomDiv label,
        .wpgv-item .wpgv-buy button,
        .wpgv-buttons .next-button,
        .wpgv-buttons #paynowbtn,
        .buying-options div.selected,
        .shipping-options div.selected,
        .wpgv_preview-box .cardDiv .voucherBottomDiv .itemtitle,
        .wpgv_preview-box .cardDiv .voucherBottomDiv .itemdescription,
        .wpgv_preview-box .cardDiv .voucherBottomDiv .termsCard,
        .wpgv_preview-box .cardDiv .voucherBottomDiv .voucherSiteInfo a {
            color:  #' . $voucher_color . '!important;
        }
        #wpgv-giftitems.loading:after {
            content: url(' . $custom_loader . ') !important;
        }
    </style>';
    $wpgv_coupon_code_type = get_option('wpgv_coupon_code_type') ? get_option('wpgv_coupon_code_type') : '';
    $wpgv_starting_coupon_number = get_option('wpgv_starting_coupon_number') ? get_option('wpgv_starting_coupon_number') : '';
    $wpgv_current_coupon_number = get_option('current_coupon_number') ? get_option('current_coupon_number') : '';
    $coupon_code_length = get_option('wpgv_coupon_code_length') ? get_option('wpgv_coupon_code_length') : 12;
    $html .= '<div class="wpgv-giftitem-wrapper"><form id="wpgv-giftitems" name="wpgv_giftitems" method="post" action="' . home_url($wp->request) . '" enctype="multipart/form-data">
        <input type="hidden" name="wpgv_coupon_code_type" id="wpgv_coupon_code_type" value="' . $wpgv_coupon_code_type . '">
        <input type="hidden" name="wpgv_starting_coupon_number" id="wpgv_starting_coupon_number" value="' . $wpgv_starting_coupon_number . '">
        <input type="hidden" name="wpgv_current_coupon_number" id="wpgv_current_coupon_number" value="' . $wpgv_current_coupon_number . '">
        <input type="hidden" name="coupon_code_length" id="coupon_code_length" value="' . $coupon_code_length . '">
        <input type="hidden" name="wpgv_giftitems_form_verify" value="' . $nonce . '">
        <input type="hidden" name="wpgv_category_id" id="category_id">
        <input type="hidden" name="wpgv_item_id" id="item_id">
        <input type="hidden" name="wpgv_total_price" id="total_price">
        <input type="hidden" name="item_pdf_price" id="item_pdf_price">
        <input type="hidden" name="wpgv_website_commission_price" id="website_commission_price" data-price="' . $wpgv_add_extra_charges . '">
        ';

    if ($shortcode_attr['item_cat_id'] != 0) {
        $wpgv_voucher_categories = get_term($shortcode_attr['item_cat_id']);
        $image_id = get_term_meta($wpgv_voucher_categories->term_id, 'wpgv-voucher-category-image-id', true);
    } else {
        // $wpgv_voucher_categories = get_categories('taxonomy=wpgv_voucher_category&post_type=wpgv_voucher_product&order_by=term_id&order=DESC');
        $wpgv_voucher_categories = get_categories(array(
            'taxonomy' => 'wpgv_voucher_category',
            'post_type' => 'wpgv_voucher_product',
            'orderby' => 'name',
            'order'   => 'ASC'
        ));
        $image_id = get_term_meta($wpgv_voucher_categories[0]->term_id, 'wpgv-voucher-category-image-id', true);
    }

    if ($wpgv_voucher_categories) {
        $image_attributes = wp_get_attachment_image_src($image_id, 'full');
        $itemimage = ($image_attributes) ? $image_attributes[0] : get_option('wpgv_demoimageurl_item');
    } else {
        $itemimage = get_option('wpgv_demoimageurl_item');
    }
    $html .= '<div class="wpgv-giftitemimage"><img src="' . $itemimage . '"></div>';

    //Step 1
    $html .= '<div id="wpgv-giftitems-step1" class="wpgv-items-wrap">
                <div class="wpgv-according-categories">';

    if ($shortcode_attr['item_id'] == 0 && $shortcode_attr['item_cat_id'] == 0) {
        foreach ($wpgv_voucher_categories as $category) {
            $html .= '<div class="wpgv-according-category" id="itemcat' . $category->term_id . '">
                                    <div class="wpgv-according-title" data-cat-id="' . $category->term_id . '"><h2>' . $category->name . '<span>' . strip_tags(term_description($category->term_id, 'wpgv_voucher_category')) . '</span></h2></div>';

            $wpgv_item_sort_by = get_option('wpgv_item_sort_by') ? get_option('wpgv_item_sort_by') : 'name';
            $string = '';
            $orderby = '';
            if ($wpgv_item_sort_by == 'high-to-low') {
                // High to Low
                $string .= "DESC";
                $orderby .= 'meta_value';
            } else if ($wpgv_item_sort_by == 'low-to-high') {
                // Low to High
                $string .= "ASC";
                $orderby .= 'meta_value';
            } else if ($wpgv_item_sort_by == 'name') {
                // Low to High
                $string .= "ASC";
                $orderby .= 'title';
            }

            $items = get_posts(
                array(
                    'posts_per_page' => -1,
                    'post_type' => 'wpgv_voucher_product',
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'wpgv_voucher_category',
                            'field' => 'term_id',
                            'terms' => $category->term_id,
                        )
                    ),
                    'meta_query' => array(
                        array(
                            'key' => 'wpgv_templates_style',
                            'value' => 'gift_items',
                        ),
                    ),
                    'orderby' => $orderby,
                    'order' => $string,
                )
            );

            $html .= '<div class="wpgv-items">';
            foreach ($items as $item) {
                $item_id = $item->ID;
                $description = get_post_meta($item_id, 'description', true);
                $price = get_post_meta($item_id, 'price', true);
                $special_price = get_post_meta($item_id, 'special_price', true);
                $subprice = ($special_price) ? $special_price : $price;
                $price_format_function = '';
                if (get_locale() == "cs_CZ") {
                    $price_format_function = 'wpgv_price_format_dot_cs';
                } else {
                    $price_format_function = 'wpgv_price_format';
                }

                $pricestring = ($special_price)
                    ? '<del>' . $price_format_function($price) . '</del> ' . (isset($price) ? '<span>' . $price_format_function($special_price) . '</span>' : '')
                    : (($price) ? '<span>' . $price_format_function($price) . '</span>' : '');

                $html .= '<div class="wpgv-item">
                            <div class="wpgv-content"><h4>' . get_the_title($item_id) . '</h4><p>' . $description . '</p></div>
                            <div class="wpgv-price">' . $pricestring . '</div>
                            <div class="wpgv-buy"><button type="button" data-item-id="' . $item_id . '" data-cat-id="' . $category->term_id . '" data-item-price="' . $subprice . '" data-item-price-pdf="' . $subprice . '">' . __('Buy', 'gift-voucher') . '</button></div>
                        </div>';
            }
            $html .= '</div>';

            $html .= '</div>';
        }
    } else if ($shortcode_attr['item_id'] != 0) {
        $single_item_args = array(
            'post_type' => 'wpgv_voucher_product',
            'post__in' => array($shortcode_attr['item_id']),
            'meta_query' => array(
                array(
                    'key' => 'wpgv_templates_style',
                    'value' => 'gift_items',
                )
            ),
        );
        $items = get_posts($single_item_args);

        $html .= '<div class="wpgv-items">';

        foreach ($items as $item) {

            $item_id = $item->ID;
            $description = get_post_meta($item_id, 'description', true);
            $price = get_post_meta($item_id, 'price', true);
            $special_price = get_post_meta($item_id, 'special_price', true);
            $subprice = ($special_price) ? $special_price : $price;
            $price_format_function = '';
            if (get_locale() == "cs_CZ") {
                $price_format_function = 'wpgv_price_format_dot_cs';
            } else {
                $price_format_function = 'wpgv_price_format';
            }


            $pricestring = ($special_price)
                ? '<del>' . $price_format_function($price) . '</del> ' . (isset($price) ? '<span>' . $price_format_function($special_price) . '</span>' : '')
                : (($price) ? '<span>' . $price_format_function($price) . '</span>' : '');

            $html .= '<div class="wpgv-item">

                    <div class="wpgv-content"><h4>' . get_the_title($item_id) . '</h4><p>' . $description . '</p></div>

                    <div class="wpgv-price">' . $pricestring . '</div>

                    <div class="wpgv-buy"><button type="button" data-item-id="' . $item_id . '" data-cat-id="' . $category->term_id . '" data-item-price="' . $subprice . '">' . __('Buy', 'gift-voucher') . '</button></div>
                </div>';
        }
        $html .= '</div>';
    } else if ($shortcode_attr['item_cat_id'] != 0) {
        $category = get_term($shortcode_attr['item_cat_id']);

        $html .= '<div class="wpgv-according-category" id="itemcat' . $category->term_id . '">
                    <div class="wpgv-according-title" data-cat-id="' . $category->term_id . '"><h2>' . $category->name . '<span>' . strip_tags(term_description($category->term_id, 'wpgv_voucher_category')) . '</span></h2></div>';
        $items = get_posts(
            array(
                'posts_per_page' => -1,
                'post_type' => 'wpgv_voucher_product',
                'meta_query' => array(
                    array(
                        'key' => 'wpgv_templates_style',
                        'value' => 'gift_items',
                    )
                ),
                'tax_query' => array(
                    array(
                        'taxonomy' => 'wpgv_voucher_category',
                        'field' => 'term_id',
                        'terms' => $category->term_id,
                    )
                )
            )
        );

        $html .= '<div class="wpgv-items">';

        foreach ($items as $item) {
            $item_id = $item->ID;
            $description = get_post_meta($item_id, 'description', true);
            $price = get_post_meta($item_id, 'price', true);
            $special_price = get_post_meta($item_id, 'special_price', true);
            $subprice = ($special_price) ? $special_price : $price;
            $price_format_function = '';
            if (get_locale() == "cs_CZ") {
                $price_format_function = 'wpgv_price_format_dot_cs';
            } else {
                $price_format_function = 'wpgv_price_format';
            }

            $pricestring = ($special_price)
                ? '<del>' . $price_format_function($price) . '</del> ' . (isset($price) ? '<span>' . $price_format_function($special_price) . '</span>' : '')
                : (($price) ? '<span>' . $price_format_function($price) . '</span>' : '');

            $html .= '<div class="wpgv-item">
                        <div class="wpgv-content"><h4>' . get_the_title($item_id) . '</h4><p>' . $description . '</p></div>
                        <div class="wpgv-price">' . $pricestring . '</div>
                        <div class="wpgv-buy"><button type="button" data-item-id="' . $item_id . '" data-cat-id="' . $category->term_id . '" data-item-price="' . $subprice . '">' . __('Buy', 'gift-voucher') . '</button></div>
                    </div>';
        }

        $html .= '</div>';
        $html .= '</div>';
    }
    $html .= '</div></div>';

    // Step 2
    $html .= '<div id="wpgv-giftitems-step2" class="wpgv-items-wrap">
                <div class="wpgv-gifttitle">
                    <h3></h3>
                    <span></span>
                </div>
                <div class="wpgv-form-fields">
                    ' . $chooseStyle . '
                </div>
                ' . $buying_for_html . '
                                <div class="wpgv-form-fields" id="wpgv-message">
                                        <label for="message">' . __('Personal Message (Optional)', 'gift-voucher') . ' (' . __('Max: 250 Characters', 'gift-voucher') . ')</label>
                                        <span class="error">' . __('Please enter no more than 250 characters.', 'gift-voucher') . '</span>
                                        <textarea name="message" id="message" class="form-field" maxlength="250"></textarea>
                                        <div class="maxchar"></div>
                                        <div class="voucher-quotes" id="voucher-quotes" style="font-size: 12px;margin: 5px 0 0; font-style: italic;' . ($has_quotes ? '' : ' display:none;') . '">
                                                <span>' . __('Quotes:', 'gift-voucher') . '</span>
                                                <style>
                                                    /* spacing and hover effect for voucher description suggestions */
                                                    #wpgv-giftitems .voucher-quotes ul li {
                                                        margin: 5px 0;
                                                        cursor: pointer;
                                                    }
                                                    #wpgv-giftitems .voucher-quotes ul li:hover {
                                                        box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
                                                    }
                                                    #wpgv-giftitems .voucher-quotes .show-more-quotes {
                                                        display: inline-block; margin-top: 6px; font-style: normal; cursor: pointer; color: #0073aa;
                                                    }
                                                    #wpgv-giftitems .voucher-quotes .show-more-quotes:hover {
                                                        text-decoration: underline;
                                                    }
                                                </style>
                                                <ul style="margin: 5px 0 0 18px; padding: 0;">
                                                ';
        if (!empty($quotes)) {
                $total_quotes = count($quotes);
                foreach ($quotes as $i => $qtext) {
                        $zebra = ($i % 2 === 0) ? $li_bg1 : $li_bg2;
                        $hidden = ($i >= 5) ? 'display:none;' : '';
                        $html .= '<li class="quote-item" style="' . $zebra . ' ' . $hidden . ' padding: 4px 6px; list-style: none;border-left: 3px solid #' . $voucher_brcolor_hex . '; border-radius: 3px; cursor: pointer;">' . esc_html($qtext) . '</li>';
                }
        }
        $html .= '
                                                </ul>
';
        if (!empty($quotes) && isset($total_quotes) && $total_quotes > 5) {
                $html .= '<a href="javascript:;" class="show-more-quotes" data-shown="5" data-step="5">' . __('Show more', 'gift-voucher') . '</a>';
        }
        $html .= '
                                        </div>
                                </div>
                <div class="wpgv-buttons">
                    <button type="button" data-next="step3" class="next-button">' . __('Continue', 'gift-voucher') . '</button>
                    <span class="back-button" data-prev="step1">' . __('Back', 'gift-voucher') . '</span>
                </div>
            </div>';

    $wpgv_allow_future_date = get_option('wpgv_allow_future_date', 0);

    if ($wpgv_allow_future_date) {
        $wpgv_allow_future_date_html = '
        <div class="form-group wpgv-form-fields voucherSelectSend">
            <label for="voucherSendType">' . __('When do you want to send a gift voucher?', 'gift-voucher') . '</label>
            <select name="voucherSendType" id="voucherSendType" class="required form-control form-field">
                <option value="send_instantly">' . __('Send instantly', 'gift-voucher') . '</option>
                <option value="send_future_date">' . __('Send on a future date', 'gift-voucher') . '</option>
            </select>
        </div>
        <div class="form-group voucherSendDatePikerRow wpgv-form-fields" style="display:none;">
            <label for="voucherSendDatePiker">' . __('Select date and time', 'gift-voucher') . '</label>
            <div class="input-group date voucherSendDatePiker" data-date="" data-date-format="dd MM yyyy - HH:ii p" data-link-field="voucherSendDate">
                <div style="display:inline-flex;width:100%">
                    <input class="form-control form-field wpgv-date-time" id="wpgv-date-time" size="16" type="text" value="" readonly>
                    <span class="input-group-addon"><span class="glyphicon-th date-add-icon" title="' . __('Add date and time', 'gift-voucher') . '"></span></span>
                    <span class="input-group-addon"><span class="glyphicon-remove date-remove-icon" title="' . __('Remove date and time', 'gift-voucher') . '"></span></span>
                </div>
                <span class="error" style="display: none;">' . __('Please enter date and time', 'gift-voucher') . '</span>
            </div>
            <input type="hidden" id="voucherSendDate" value="" /><br/>
        </div>';
    } else {
        $wpgv_allow_future_date_html = '<input type="hidden" id="voucherSendType" value="send_instantly">';
    }

    // Step 3
    if ($setting_options->post_shipping) {
        $html .= '<div id="wpgv-giftitems-step3" class="wpgv-items-wrap">
                <div class="shipping flex-field">
                    <label>' . __('Shipping', 'gift-voucher') . '</label>
                    <div class="shipping-options">
                        <div class="shipping_as_email selected" data-value="shipping_as_email">
                            <img src="' . WPGIFT__PLUGIN_URL . '/assets/img/envelope.png">
                            <span>' . __('Email', 'gift-voucher') . '</span>
                        </div>
                        <div class="shipping_as_post" data-value="shipping_as_post">
                            <img src="' . WPGIFT__PLUGIN_URL . '/assets/img/delivery-truck.png">
                            <span>' . __('Post', 'gift-voucher') . '</span>
                        </div>
                    </div>
                    <input type="hidden" name="shipping" id="shipping" value="shipping_as_email">
                </div>
                <div class="wpgv-form-fields" id="wpgv-shipping_email">
                    <label>' . __('Send the voucher to recipient email here', 'gift-voucher') . '</label>
                    <span class="error">' . __('Please enter email.', 'gift-voucher') . '</span>
                    <input type="email" name="shipping_email" id="shipping_email" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-receipt_email">
                    <label>' . __('Your email address (for the receipt)', 'gift-voucher') . '</label>
                    <span class="error">' . __('Please enter email.', 'gift-voucher') . '</span>
                    <span class="eqlerror">' . __('Your email address is required.', 'gift-voucher') . '</span>
                    <input type="email" name="receipt_email" id="receipt_email" class="form-field">
                </div>' . $wpgv_allow_future_date_html;

        if (isset($invoice_options->is_invoice_active) && $invoice_options->is_invoice_active == 1) {
            $html .= '<div class="wpgv-form-fields" id="wpgv-company_name">
                    <label>' . __('Company Name (for invoice)', 'gift-voucher') . '</label>
                    <span class="error">' . __('Your Company name is required', 'gift-voucher') . '</span>
                    <input type="email" name="company_name" id="company_name" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-address_line1">
                    <label>' . __('Address Line 1', 'gift-voucher') . '</label>
                    <input type="email" name="address_line1" id="address_line1" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-address_line2">
                    <label>' . __('Address Line 2', 'gift-voucher') . '</label>
                    <input type="email" name="address_line2" id="address_line2" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-address_line3">
                    <label>' . __('Address Line 3', 'gift-voucher') . '</label>
                    <input type="email" name="address_line3" id="address_line3" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-address_line4">
                    <label>' . __('Address Line 4', 'gift-voucher') . '</label>
                    <input type="email" name="address_line4" id="address_line4" class="form-field">
                </div>';
        }


        $html .= '<div class="wpgv-form-fields" id="wpgv-post_name">
                    <label>' . __('Shipping address', 'gift-voucher') . '</label>
                    <input type="text" name="post_firstname" id="post_firstname" placeholder="' . __('First Name', 'gift-voucher') . '" class="form-field half-field first" />
                    <input type="text" name="post_lastname" id="post_lastname" placeholder="' . __('Last Name', 'gift-voucher') . '" class="form-field half-field" />
                    <input type="text" name="post_address" id="post_address" placeholder="' . __('Address', 'gift-voucher') . '" class="form-field" />
                    <input type="text" name="post_code" id="post_code" placeholder="' . __('Postcode', 'gift-voucher') . '" class="form-field" />
                </div>
                <div class="wpgv-form-fields" id="wpgv-shipping_method">
                    <label id="shipping_method">' . __('Shipping method', 'gift-voucher') . '</label>
                    ' . $shipping_methods_string . '
                </div>
                <div class="order_details_preview">
                    <h3>' . __('Your Order', 'gift-voucher') . '</h3>
                    <div class="wpgv_preview_box">
                        <div>
                            <h4 class="wpgv-itemtitle">-</h4>
                            <span>' . __('Your Name', 'gift-voucher') . ': <i id="autoyourname"></i></span>
                        </div>
                        ' . (($setting_options->currency_position == 'Left') ? '<div id="itemprice">' . $setting_options->currency . ' <span></span> </div>' : '<div id="itemprice"> <span></span> ' . $setting_options->currency . '</div>') . '
                    </div>
                    <div class="wpgv_shipping_box">
                        <div>
                            <h4>' . __('Shipping', 'gift-voucher') . '</h4>
                        </div>
                        ' . (($setting_options->currency_position == 'Left') ? '<div id="shippingprice">' . $setting_options->currency . ' <span></span> </div>' : '<div id="shippingprice"> <span></span> ' . $setting_options->currency . '</div>') . '
                    </div>
                    ' . ($wpgv_add_extra_charges ? '<div class="wpgv_commission_box"><div><h4>' . $wpgv_additional_charges_text . '</h4></div><div id="commissionprice">' . wpgv_price_format($wpgv_add_extra_charges) . '</div></div>' : '') . '
                    <div class="wpgv_total_box">
                        <div>
                            <h4><b>' . __('Total', 'gift-voucher') . '</b></h4>
                        </div>
                        ' . (($setting_options->currency_position == 'Left') ? '<div id="totalprice"><b>' . $setting_options->currency . ' <span></span> </b></div>' : '<div id="totalprice"><b> <span></span> ' . $setting_options->currency . '</b></div>') . '
                    </div>';
        if ($setting_options->preview_button) {
            $html .= '<div class="preview-box"><button type="button" id="itempreview" data-url="' . get_site_url() . '/gift-item-pdf-preview/?action=preview&nonce=' . $nonce . '">' . __('Show Preview as PDF', 'gift-voucher') . '</button></div>';
        }
        $html .= '</div>
                <div class="wpgv-form-fields paymentcount' . $paymentCount . '" id="wpgv_payment_gateway">
                    <label>' . __('Payment Method', 'gift-voucher') . '</label>
                    ' . $paymenyGateway . '
                </div>
                <div class="acceptVoucherTerms">
                    <label><input type="checkbox" class="required" name="acceptVoucherTerms"> ' . stripslashes($wpgv_termstext) . '</label>
                </div>
                <div class="voucherNote">' . $setting_options->voucher_terms_note . '</div>
                <div class="wpgv-buttons">';
        // google reCAPTCHA v2
        if (get_option('wpgv_enable_recaptcha') == 1 && get_option('wpgv_recaptcha_site_key')) {
            $html .= '<div class="g-recaptcha" id="g_recaptcha_v2" data-sitekey="' . esc_attr(get_option('wpgv_recaptcha_site_key')) . '"></div>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>';
        }
        // google reCAPTCHA v2
        $html .= '<button type="button" data-next="step4" id="paynowbtn" data-url="action=wpgv_doajax_item_pdf_save_func&nonce=' . $nonce . '">' . __('Pay Now', 'gift-voucher') . ' - ' . (($setting_options->currency_position == 'Left') ? $setting_options->currency . ' <span></span> ' : ' <span></span> ' . $setting_options->currency) . '</button>
                    <span data-prev="step2" class="back-button">' . __('Back', 'gift-voucher') . '</span>
                </div>
            </div>';
    } else {
        $html .= '<div id="wpgv-giftitems-step3" class="wpgv-items-wrap">
                <input type="hidden" name="shipping" id="shipping" value="shipping_as_email">
                <div class="wpgv-form-fields" id="wpgv-shipping_email">
                    <label>' . __('Send the voucher to recipient email here', 'gift-voucher') . '</label>
                    <span class="error">' . __('Required', 'gift-voucher') . '</span>
                    <input type="email" name="shipping_email" id="shipping_email" class="form-field">
                </div>
                <div class="wpgv-form-fields" id="wpgv-receipt_email">
                    <label>' . __('Your email address (for the receipt)', 'gift-voucher') . '</label>
                    <span class="error">' . __('Your email address is required', 'gift-voucher') . '</span>
                    <input type="email" name="receipt_email" id="receipt_email" class="form-field">
                </div>';

        if (isset($invoice_options->is_invoice_active) && $invoice_options->is_invoice_active == 1) {
            $html .= '<div class="wpgv-form-fields" id="wpgv-company_name">
                        <label>' . __('Company Name (for invoice)', 'gift-voucher') . '</label>
                        <span class="error">' . __('Your Company name is required', 'gift-voucher') . '</span>
                        <input type="email" name="company_name" id="company_name" class="form-field">
                    </div>
                    <div class="wpgv-form-fields" id="wpgv-address_line1">
                        <label>' . __('Address Line 1', 'gift-voucher') . '</label>
                        <input type="email" name="address_line1" id="address_line1" class="form-field">
                    </div>
                    <div class="wpgv-form-fields" id="wpgv-address_line2">
                        <label>' . __('Address Line 2', 'gift-voucher') . '</label>
                        <input type="email" name="address_line2" id="address_line2" class="form-field">
                    </div>
                    <div class="wpgv-form-fields" id="wpgv-address_line3">
                        <label>' . __('Address Line 3', 'gift-voucher') . '</label>
                        <input type="email" name="address_line3" id="address_line3" class="form-field">
                    </div>
                    <div class="wpgv-form-fields" id="wpgv-address_line4">
                        <label>' . __('Address Line 4', 'gift-voucher') . '</label>
                        <input type="email" name="address_line4" id="address_line4" class="form-field">
                    </div>';
        }

        $html .= '<div class="order_details_preview">
    <h3>' . __('Your Order', 'gift-voucher') . '</h3>

    <div class="wpgv_preview_box">
        <div>
            <h4 class="wpgv-itemtitle">-</h4>
            <span>' . __('Your Name', 'gift-voucher') . ': <i id="autoyourname"></i></span>
        </div>
        ' . (($setting_options->currency_position == 'Left')
            ? '<div id="itemprice">' . $setting_options->currency . ' <span></span> </div>'
            : '<div id="itemprice"> <span></span> ' . $setting_options->currency . '</div>') . '
    </div>

    ' . ($wpgv_add_extra_charges
            ? '<div class="wpgv_commission_box">
                <div><h4>' . $wpgv_additional_charges_text . '</h4></div>
                <div id="commissionprice">' . wpgv_price_format($wpgv_add_extra_charges) . '</div>
            </div>'
            : '') . '
';

        if ($setting_options->preview_button) {
            $html .= '<div class="preview-box"><button type="button" id="itempreview" data-url="' . get_site_url() . '/gift-item-pdf-preview/?action=preview&nonce=' . $nonce . '">' . __('Show Preview as PDF', 'gift-voucher') . '</button></div>';
        }
        $html .= '</div>
                <div class="wpgv-form-fields paymentcount' . $paymentCount . '" id="wpgv_payment_gateway">
                    <label>' . __('Payment Method', 'gift-voucher') . '</label>
                    ' . $paymenyGateway . '
                </div>
                <div class="acceptVoucherTerms">
                    <label><input type="checkbox" class="required" name="acceptVoucherTerms"> ' . stripslashes($wpgv_termstext) . '</label>
                </div>
                <div class="voucherNote">' . $setting_options->voucher_terms_note . '</div>
                <div class="wpgv-buttons">';
        // google reCAPTCHA v2
        if (get_option('wpgv_enable_recaptcha') == 1 && get_option('wpgv_recaptcha_site_key')) {
            $html .= '<div class="g-recaptcha" id="g_recaptcha_v2" data-sitekey="' . esc_attr(get_option('wpgv_recaptcha_site_key')) . '"></div>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>';
        }
        // google reCAPTCHA v2
        $html .= '<button type="button" data-next="step4" id="paynowbtn" data-url="action=wpgv_doajax_item_pdf_save_func&nonce=' . $nonce . '">' . __('Pay Now', 'gift-voucher') . '</button>
                    <span data-prev="step2" class="back-button">' . __('Back', 'gift-voucher') . '</span>
                </div>
            </div>';
    }

    $html .= '</form>';

    // Add Klarna Payments Modal (shared template) - only if Klarna is enabled
    if (get_option('wpgv_klarna')) {
        require_once WPGIFT__PLUGIN_DIR . '/include/klarna-modal-template.php';
        $html .= wpgv_get_klarna_modal_html();
    }

    $htmlstyle1 = '<div class="wpgv_preview-box wpgvstyle1">
                <div class="cardDiv">
                    <div class="cardImgTop">
                        <img class="uk-thumbnail" src="' . $itemimage . '">
                    </div>
                    <div class="voucherBottomDiv">
                        <h2 class="itemtitle"></h2>
                        <p class="itemdescription"></p>
                        <div class="uk-form-row">
                            <div class="nameFormLeft">
                                <label>' . __('Your Name', 'gift-voucher') . '</label>
                                <input type="text" name="forNameCard" class="forNameCard" readonly>
                            </div>
                            <div class="nameFormRight">
                                <label>' . __('Recipient Name', 'gift-voucher') . '</label>
                                <input type="text" name="fromNameCard" class="fromNameCard" readonly>
                            </div>
                            ' . $voucher_value_html . '
                            <div class="messageForm">
                                <label>' . __('Personal Message', 'gift-voucher') . '</label>
                                <textarea name="personalMessageCard" class="personalMessageCard" readonly></textarea>
                            </div>
                            <div class="expiryFormLeft">
                                <label>' . __('Date of Expiry', 'gift-voucher') . '</label>
                                <input type="text" name="expiryCard" class="expiryCard" value="' . $expiryCard . '" readonly>
                            </div>
                            <div class="codeFormRight">
                                <label>' . __('Coupon Code', 'gift-voucher') . '</label>
                                <input type="text" name="codeCard" class="codeCard" readonly value="6234256841004311">
                            </div>
                            <div class="clearfix"></div>
                            <div class="voucherSiteInfo"><a href="' . $setting_options->pdf_footer_url . '">' . $setting_options->pdf_footer_url . '</a> | <a href="mailto:' . $setting_options->pdf_footer_email . '">' . $setting_options->pdf_footer_email . '</a></div>
                            <div class="termsCard">* ' . $wpgv_leftside_notice . '</div>
                        </div>
                    </div>
                    <h3>' . __('Voucher Preview', 'gift-voucher') . '</h3>
                </div>
        </div>';

    $htmlstyle2 = '<div class="wpgv_preview-box wpgvstyle2">
                <div class="cardDiv">
                    <div class="voucherBottomDiv">
                        <div class="cardImgTop">
                            <img class="uk-thumbnail" src="' . $itemimage . '">
                        </div>
                        <div class="sidedetails">
                            <h2 class="itemtitle"></h2>
                            <p class="itemdescription"></p>
                            <div class="nameFormLeft">
                                <label>' . __('Your Name', 'gift-voucher') . '</label>
                                <input type="text" name="forNameCard" class="forNameCard" readonly>
                            </div>
                            <div class="nameFormRight">
                                <label>' . __('Recipient Name', 'gift-voucher') . '</label>
                                <input type="text" name="fromNameCard" class="fromNameCard" readonly>
                            </div>
                            ' . $voucher_value_html . '
                        </div>
                        <div class="uk-form-row">
                            <div class="messageForm">
                                <label>' . __('Personal Message', 'gift-voucher') . '</label>
                                <textarea name="personalMessageCard" class="personalMessageCard" readonly></textarea>
                            </div>
                            <div class="expiryFormLeft">
                                <label>' . __('Date of Expiry', 'gift-voucher') . '</label>
                                <input type="text" name="expiryCard" class="expiryCard" value="' . $expiryCard . '" readonly>
                            </div>
                            <div class="codeFormRight">
                                <label>' . __('Coupon Code', 'gift-voucher') . '</label>
                                <input type="text" name="codeCard" class="codeCard" readonly value="6234256815004311">
                            </div>
                            <div class="clearfix"></div>
                            <div class="voucherSiteInfo"><a href="' . $setting_options->pdf_footer_url . '">' . $setting_options->pdf_footer_url . '</a> | <a href="mailto:' . $setting_options->pdf_footer_email . '">' . $setting_options->pdf_footer_email . '</a></div>
                            <div class="termsCard">* ' . $wpgv_leftside_notice . '</div>
                        </div>
                    </div>
                    <h3>' . __('Voucher Preview', 'gift-voucher') . '</h3>
                </div>
        </div>';

    $htmlstyle3 = '<div class="wpgv_preview-box wpgvstyle3">
                <div class="cardDiv">
                    <div class="voucherBottomDiv">
                        <h2 class="itemtitle"></h2>
                        <p class="itemdescription"></p>
                        <div class="cardImgTop">
                            <img class="uk-thumbnail" src="' . $itemimage . '">
                        </div>
                        <div class="sidedetails">
                            <div class="nameFormLeft">
                                <label>' . __('Your Name', 'gift-voucher') . '</label>
                                <input type="text" name="forNameCard" class="forNameCard" readonly>
                            </div>
                            <div class="nameFormRight">
                                <label>' . __('Recipient Name', 'gift-voucher') . '</label>
                                <input type="text" name="fromNameCard" class="fromNameCard" readonly>
                            </div>
                            ' . $voucher_value_html . '
                        </div>
                        <div class="uk-form-row">
                            <div class="messageForm">
                                <label>' . __('Personal Message', 'gift-voucher') . '</label>
                                <textarea name="personalMessageCard" class="personalMessageCard" readonly></textarea>
                            </div>
                            <div class="expiryFormLeft">
                                <label>' . __('Date of Expiry', 'gift-voucher') . '</label>
                                <input type="text" name="expiryCard" class="expiryCard" value="' . $expiryCard . '" readonly>
                            </div>
                            <div class="codeFormRight">
                                <label>' . __('Coupon Code', 'gift-voucher') . '</label>
                                <input type="text" name="codeCard" class="codeCard" readonly value="">
                            </div>
                            <div class="clearfix"></div>
                            <div class="voucherSiteInfo"><a href="' . $setting_options->pdf_footer_url . '">' . $setting_options->pdf_footer_url . '</a> | <a href="mailto:' . $setting_options->pdf_footer_email . '">' . $setting_options->pdf_footer_email . '</a></div>
                            <div class="termsCard">* ' . $wpgv_leftside_notice . '</div>
                        </div>
                    </div>
                    <h3>' . __('Voucher Preview', 'gift-voucher') . '</h3>
                </div>
        </div>';

    $voucherstyle = '';
    if ($setting_options->is_style_choose_enable) {
        $voucher_styles = json_decode($setting_options->voucher_style);
        foreach ($voucher_styles as $key => $value) {
            $html .= ${'htmlstyle' . ($value + 1)};
        }
    } else {
        switch ($setting_options->voucher_style) {
            case 0:
                $html .= $htmlstyle1;
                break;
            case 1:
                $html .= $htmlstyle2;
                break;
            case 2:
                $html .= $htmlstyle3;
                break;
            default:
                $html .= $htmlstyle1;
                break;
        }
    }

    $html .= '</div><style>' . $wpgv_custom_css . '</style>';

    return $html;
}

function wpgv__doajax_get_itemcat_image()
{

    $catid = $_REQUEST['catid'];
    $image_id = get_term_meta($catid, 'wpgv-voucher-category-image-id', true);
    $image_attributes = wp_get_attachment_image_src($image_id, 'full');
    $itemimage = ($image_attributes) ? $image_attributes[0] : get_option('wpgv_demoimageurl_item');
    echo wp_send_json(array('image' => $itemimage));
    wp_die();
}

function wpgv__doajax_get_item_data()
{
    $item_id = $_REQUEST['itemid'];
    $image_styles = array();
    for ($i = 0; $i < 3; $i++) {
        $style_image = get_post_meta($item_id, 'style' . ($i + 1) . '_image', true);
        $image_attributes = wp_get_attachment_image_src($style_image, 'voucher-medium');
        $image_styles[] = ($image_attributes) ? $image_attributes[0] : get_option('wpgv_demoimageurl_item');
    }
    echo wp_send_json(array('title' => strip_tags(get_the_title($item_id)), 'images' => $image_styles, 'description' => html_entity_decode(strip_tags(get_post_meta($item_id, 'description', true))), 'price' => get_post_meta($item_id, 'price', true), 'special_price' => get_post_meta($item_id, 'special_price', true)));
    wp_die();
}

add_shortcode('wpgv_giftitems', 'wpgv_giftitems_shortcode');
add_action('wp_ajax_nopriv_wpgv_doajax_get_itemcat_image', 'wpgv__doajax_get_itemcat_image');
add_action('wp_ajax_wpgv_doajax_get_itemcat_image', 'wpgv__doajax_get_itemcat_image');
add_action('wp_ajax_nopriv_wpgv_doajax_get_item_data', 'wpgv__doajax_get_item_data');
add_action('wp_ajax_wpgv_doajax_get_item_data', 'wpgv__doajax_get_item_data');
