/**
  * Check item is already exist in order
  * 
  * Handles to check the item is already exist in order or not
  * 
  * @package WooCommerce - PDF Vouchers
  * @since 2.0
  */
 public function woo_vou_generate_pdf_voucher($email = '', $product_id = '', $download_id = '', $order_id = '', $item_id = '')
 {
     $prefix = WOO_VOU_META_PREFIX;
     $vou_codes_key = $this->woo_vou_get_multi_voucher_key($order_id, $product_id, $item_id);
     //Get mutiple pdf option from order meta
     $multiple_pdf = empty($order_id) ? '' : get_post_meta($order_id, $prefix . 'multiple_pdf', true);
     $orderdvoucodes = array();
     if (!empty($multiple_pdf)) {
         $orderdvoucodes = $this->woo_vou_get_multi_voucher($order_id, $product_id, $item_id);
     }
     // Check out voucher download key
     if (in_array($download_id, $vou_codes_key) || $download_id == 'woo_vou_pdf_1') {
         //product voucher pdf
         woo_vou_process_product_pdf($product_id, $order_id, $item_id, $orderdvoucodes);
     }
 }
 /**
  * Handles the functionality to attach the voucher pdf in mail
  *
  * @package WooCommerce - PDF Vouchers
  * @since   2.0
  */
 public function woo_vou_attach_voucher_to_email($attachments, $status, $order)
 {
     // Taking status array
     $vou_status = array('customer_processing_order', 'customer_completed_order', 'customer_invoice');
     // Taking order status array
     $vou_order_status = array('wc-completed');
     $order_status = !empty($order->post_status) ? $order->post_status : '';
     // Order status
     $vou_attach_mail = get_option('vou_attach_mail');
     // Getting voucher attach option
     $grant_access_after_payment = get_option('woocommerce_downloads_grant_access_after_payment');
     // Woocommerce grant access after payment
     if ($vou_attach_mail == 'yes' && !empty($order) && (in_array($status, $vou_status) && in_array($order_status, $vou_order_status) || $status == 'customer_processing_order' && $grant_access_after_payment == 'yes' && $order_status != 'wc-on-hold')) {
         $prefix = WOO_VOU_META_PREFIX;
         $vou_attachments = array();
         $order_id = !empty($order->id) ? $order->id : '';
         // Taking order id
         $cart_details = new Wc_Order($order_id);
         $order_items = $cart_details->get_items();
         if (!empty($order_items)) {
             //not empty items
             //foreach items
             foreach ($order_items as $item_id => $download_data) {
                 $product_id = !empty($download_data['product_id']) ? $download_data['product_id'] : '';
                 $variation_id = !empty($download_data['variation_id']) ? $download_data['variation_id'] : '';
                 //Get data id vriation id or product id
                 $data_id = !empty($variation_id) ? $variation_id : $product_id;
                 //Check voucher enable or not
                 $enable_voucher = $this->model->woo_vou_check_enable_voucher($product_id, $variation_id);
                 if ($enable_voucher) {
                     // Get mutiple pdf option from order meta
                     $multiple_pdf = !empty($order_id) ? get_post_meta($order_id, $prefix . 'multiple_pdf', true) : '';
                     $orderdvoucodes = array();
                     if ($multiple_pdf == 'yes') {
                         $orderdvoucodes = $this->model->woo_vou_get_multi_voucher($order_id, $data_id, $item_id);
                     } else {
                         $orderdvoucodes['woo_vou_pdf_1'] = '';
                     }
                     // If order voucher codes are not empty
                     if (!empty($orderdvoucodes)) {
                         foreach ($orderdvoucodes as $orderdvoucode_key => $orderdvoucode_val) {
                             if (!empty($orderdvoucode_key)) {
                                 $attach_pdf_file_name = get_option('attach_pdf_name');
                                 $attach_pdf_file_name = isset($attach_pdf_file_name) ? $attach_pdf_file_name : 'woo-voucher-';
                                 //Get Pdf Key
                                 $pdf_vou_key = $orderdvoucode_key;
                                 // Replacing voucher pdf name with given value
                                 $orderdvoucode_key = str_replace('woo_vou_pdf_', $attach_pdf_file_name, $orderdvoucode_key);
                                 // Voucher pdf path and voucher name
                                 $vou_pdf_path = WOO_VOU_UPLOAD_DIR . $orderdvoucode_key . '-' . $data_id . '-' . $item_id . '-' . $order_id;
                                 // Voucher pdf path
                                 $vou_pdf_name = $vou_pdf_path . '.pdf';
                                 // If voucher pdf does not exist in folder
                                 if (!file_exists($vou_pdf_name)) {
                                     $pdf_args = array('pdf_vou_key' => $pdf_vou_key, 'pdf_name' => $vou_pdf_path, 'save_file' => true);
                                     //Generatin pdf
                                     woo_vou_process_product_pdf($data_id, $order_id, $item_id, $orderdvoucodes, $pdf_args);
                                 }
                                 // If voucher pdf exist in folder
                                 if (file_exists($vou_pdf_name)) {
                                     $attachments[] = $vou_pdf_name;
                                     // Adding the voucher pdf in attachment array
                                 }
                             }
                         }
                     }
                     // End of orderdvoucodes
                 }
             }
         }
         // End of order item
     }
     return $attachments;
 }