/**
     * Voucher data meta box
     *
     * @since 1.2
     */
    public function data_meta_box($post)
    {
        wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce');
        $voucher = new WC_Voucher($post->ID);
        $default_fonts = array('Helvetica' => 'Helvetica', 'Courier' => 'Courier', 'Times' => 'Times', 'Roboto' => 'Roboto', 'Merriweather' => 'Merriweather');
        $available_fonts = array_merge(array('' => ''), $default_fonts);
        // since this little snippet of css applies only to the voucher post page, it's easier to have inline here
        ?>
		<style type="text/css">
			#misc-publishing-actions { display:none; }
			#edit-slug-box { display:none }
			.imgareaselect-outer { cursor: crosshair; }
		</style>
		<div id="voucher_options" class="panel woocommerce_options_panel">
			<div class="options_group">
				<?php 
        // Text color
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher', 'label' => __('Default Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $default_fonts, 'font_size_default' => 11));
        woocommerce_wp_text_input(array('id' => '_voucher_font_color', 'label' => __('Default Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'default' => '#000000', 'description' => __('The default text color for the voucher.', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'class' => 'colorpick'));
        woocommerce_wp_select(array('id' => '_voucher_text_align', 'label' => __('Default Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The default text alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => array('L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Product name position
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'product_name_pos', 'label' => __('Product Name Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('product_name')), 'description' => __('Optional position of the product name', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_product_name_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('product_name'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_product_name', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_product_name_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_name']['font']['color']) ? $voucher->voucher_fields['product_name']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_select(array('id' => '_product_name_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_name']['text_align']) ? $voucher->voucher_fields['product_name']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // SKU position
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'product_sku_pos', 'label' => __('SKU Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('product_sku')), 'description' => __('Optional position of the product SKU', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_product_sku_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('product_sku'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_product_sku', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_product_sku_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_sku']['font']['color']) ? $voucher->voucher_fields['product_sku']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_select(array('id' => '_product_sku_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_sku']['text_align']) ? $voucher->voucher_fields['product_sku']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Voucher number position
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'voucher_number_pos', 'label' => __('Voucher Number Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('voucher_number')), 'description' => __('Optional position of the voucher number', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_voucher_number_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('voucher_number'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher_number', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_voucher_number_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_number']['font']['color']) ? $voucher->voucher_fields['voucher_number']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_select(array('id' => '_voucher_number_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_number']['text_align']) ? $voucher->voucher_fields['voucher_number']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Product price
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'voucher_product_price_pos', 'label' => __('Product Price Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('voucher_product_price')), 'description' => __('Optional position of the product price', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_voucher_product_price_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('voucher_product_price'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher_product_price', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_voucher_product_price_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_product_price']['font']['color']) ? $voucher->voucher_fields['voucher_product_price']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_select(array('id' => '_voucher_product_price_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_product_price']['text_align']) ? $voucher->voucher_fields['voucher_product_price']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Days to expiration
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'expiration_date_pos', 'label' => __('Expiration Date Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('expiration_date')), 'description' => __('Optional position of the voucher expiration date', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_expiration_date_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('expiration_date'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_expiration_date', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_expiration_date_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['expiration_date']['font']['color']) ? $voucher->voucher_fields['expiration_date']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_text_input(array('id' => '_days_to_expiry', 'label' => __('Days to Expiration', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Optional number of days after purchase until the voucher expires', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('days', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_expiry()));
        woocommerce_wp_select(array('id' => '_expiration_date_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['expiration_date']['text_align']) ? $voucher->voucher_fields['expiration_date']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Voucher recipient position
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'recipient_name_pos', 'label' => __('Recipient Name Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('recipient_name')), 'description' => __('Optional position of the name of the receiving party.', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_recipient_name_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('recipient_name'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_recipient_name', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_recipient_name_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['font']['color']) ? $voucher->voucher_fields['recipient_name']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_text_input(array('id' => '_recipient_name_max_length', 'label' => __('Max Length', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The maximum length of the recipient name field', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('No Limit', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_user_input_field_max_length('recipient_name')));
        woocommerce_wp_text_input(array('id' => '_recipient_name_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['label']) ? $voucher->voucher_fields['recipient_name']['label'] : 'Recipient Name'));
        woocommerce_wp_checkbox(array('id' => '_recipient_name_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the Recipient Name option without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('recipient_name') ? 'yes' : 'no'));
        woocommerce_wp_checkbox(array('id' => '_recipient_name_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('recipient_name') ? 'yes' : 'no'));
        woocommerce_wp_select(array('id' => '_recipient_name_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['text_align']) ? $voucher->voucher_fields['recipient_name']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Voucher recipient email option
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'recipient_email_pos', 'label' => __('Recipient Email Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('recipient_email_pos')), 'description' => __('Optional position of the user-supplied recipient email', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_recipient_email_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('recipient_email_pos'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_recipient_email', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_recipient_email_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_email']['font']['color']) ? $voucher->voucher_fields['recipient_email']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_text_input(array('id' => '_recipient_email_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_email']['label']) ? $voucher->voucher_fields['recipient_email']['label'] : 'Recipient Email'));
        woocommerce_wp_checkbox(array('id' => '_recipient_email_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the Recipient Email option without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('recipient_email') ? 'yes' : 'no'));
        woocommerce_wp_checkbox(array('id' => '_recipient_email_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('recipient_email') ? 'yes' : 'no'));
        woocommerce_wp_select(array('id' => '_message_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['text_align']) ? $voucher->voucher_fields['message']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        // Voucher message position
        echo '<div class="options_group">';
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'message_pos', 'label' => __('Message Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('message')), 'description' => __('Optional position of the user-supplied message', WC_PDF_Product_Vouchers::TEXT_DOMAIN)));
        woocommerce_wp_hidden_input(array('id' => '_message_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('message'))));
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_message', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts));
        woocommerce_wp_text_input(array('id' => '_message_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['font']['color']) ? $voucher->voucher_fields['message']['font']['color'] : '', 'class' => 'colorpick'));
        woocommerce_wp_text_input(array('id' => '_message_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['label']) ? $voucher->voucher_fields['message']['label'] : 'Message to Recipient'));
        woocommerce_wp_text_input(array('id' => '_message_max_length', 'label' => __('Max Length', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The maximum length of the message field', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('No Limit', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_user_input_field_max_length('message')));
        woocommerce_wp_checkbox(array('id' => '_message_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the customer to be able to add a personalized message that will be included in the recipient email without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('message') ? 'yes' : 'no'));
        woocommerce_wp_checkbox(array('id' => '_message_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('message') ? 'yes' : 'no'));
        woocommerce_wp_select(array('id' => '_message_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['text_align']) ? $voucher->voucher_fields['message']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN))));
        echo '</div>';
        ?>
			</div>
		</div>
		<?php 
        WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_color_picker_js();
    }
 /**
  * Make sure the user-input voucher fields are persisted to the database in the
  * order item meta.  This is called during the checkout process for each
  * cart item added to the order.  Requires WooCommerce 2.0+
  *
  * @since 1.2
  * @param int $item_id item identifier
  * @param array $values array of data representing a cart item
  */
 public function add_order_item_meta($item_id, $values)
 {
     // is this a voucher product?
     if (isset($values['voucher_id'])) {
         $voucher = new WC_Voucher($values['voucher_id']);
         wc_add_order_item_meta($item_id, '_voucher_image_id', $values['voucher_image_id']);
         wc_add_order_item_meta($item_id, '_voucher_id', $values['voucher_id']);
         wc_add_order_item_meta($item_id, '_voucher_redeem', array_pad(array(), $values['quantity'], null));
         wc_add_order_item_meta($item_id, '_voucher_number', WC_PDF_Product_Vouchers_Voucher::generate_voucher_number());
         // set any user-input fields to the order item meta data (which can be displayed on the frontend)
         // ie recipient_name, message
         if (isset($values['voucher_item_meta_data'])) {
             foreach ($values['voucher_item_meta_data'] as $name => $value) {
                 if ($voucher->is_user_input_type_field($name) && $value) {
                     // make sure any max length rules are imposed
                     if ($voucher->get_user_input_field_max_length($name)) {
                         $value = substr($value, 0, $voucher->get_user_input_field_max_length($name));
                     }
                     wc_add_order_item_meta($item_id, __($voucher->get_field_label($name), WC_PDF_Product_Vouchers::TEXT_DOMAIN), $value);
                 }
             }
         }
     }
 }