Exemplo n.º 1
0
    ?>
</th>
			<th width="5%"><?php 
    echo __('Qty', 'woovoucher');
    ?>
</th>
		</tr><?php 
    foreach ($order_items as $item_id => $product_data) {
        //Get product from Item ( It is required otherwise multipdf voucher link not work )
        $_product = apply_filters('woocommerce_order_item_product', $cart_details->get_product_from_item($product_data), $product_data);
        if (!$_product) {
            //If product deleted
            $download_file_data = array();
        } else {
            //Get download files
            $download_file_data = $cart_details->get_item_downloads($product_data);
        }
        //Get product ID
        $product_id = $product_data['product_id'];
        //get all voucher details from order meta
        $allvoucherdata = isset($allorderdata[$product_id]) ? $allorderdata[$product_id] : array();
        //Get product item meta
        $product_item_meta = isset($product_data['item_meta']) ? $product_data['item_meta'] : array();
        //Get voucher code from item meta "Now we store voucher codes in item meta fields"
        $codes_item_meta = wc_get_order_item_meta($item_id, $prefix . 'codes');
        if (!empty($codes_item_meta)) {
            // Check Voucher Data are not empty
            ?>
				
				<tr>
					<td class="woo-vou-history-td"><img src="<?php 
Exemplo n.º 2
0
 /**
  * Adding Hooks
  *
  * Adding proper hoocks for the discount codes
  *
  * @package WooCommerce - PDF Vouchers
  * @since   2.3.1
  */
 public function woo_vou_my_pdf_vouchers_download_link($downloads = array())
 {
     //get prefix
     $prefix = WOO_VOU_META_PREFIX;
     if (is_user_logged_in()) {
         //If user is logged in
         //Get user ID
         $user_id = get_current_user_id();
         //Get User Order Arguments
         $args = array('numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user_id, 'post_type' => WOO_VOU_MAIN_SHOP_POST_TYPE, 'post_status' => array('wc-completed'), 'meta_query' => array(array('key' => $prefix . 'meta_order_details', 'compare' => 'EXISTS')));
         //user orders
         $user_orders = get_posts($args);
         if (!empty($user_orders)) {
             //If orders are not empty
             foreach ($user_orders as $user_order) {
                 //Get order ID
                 $order_id = isset($user_order->ID) ? $user_order->ID : '';
                 if (!empty($order_id)) {
                     //Order it not empty
                     global $vou_order;
                     //Set global order ID
                     $vou_order = $order_id;
                     //Get cart details
                     $cart_details = new Wc_Order($order_id);
                     $order_items = $cart_details->get_items();
                     $order_date = isset($cart_details->order_date) ? $cart_details->order_date : '';
                     $order_date = date('d-m-y', strtotime($order_date));
                     if (!empty($order_items)) {
                         // Check cart details are not empty
                         foreach ($order_items as $item_id => $product_data) {
                             //Get product from Item ( It is required otherwise multipdf voucher link not work )
                             $_product = apply_filters('woocommerce_order_item_product', $cart_details->get_product_from_item($product_data), $product_data);
                             if (!$_product) {
                                 //If product deleted
                                 $download_file_data = array();
                             } else {
                                 //Get download files
                                 $download_file_data = $cart_details->get_item_downloads($product_data);
                             }
                             //Get voucher codes
                             $codes = wc_get_order_item_meta($item_id, $prefix . 'codes');
                             if (!empty($download_file_data) && !empty($codes)) {
                                 //If download exist and code is not empty
                                 foreach ($download_file_data as $key => $download_file) {
                                     //check download key is voucher key or not
                                     $check_key = strpos($key, 'woo_vou_pdf_');
                                     //get voucher number
                                     $voucher_number = str_replace('woo_vou_pdf_', '', $key);
                                     if (empty($voucher_number)) {
                                         //If empty voucher number
                                         $voucher_number = 1;
                                     }
                                     if (!empty($download_file) && $check_key !== false) {
                                         //Get download URL
                                         $download_url = $download_file['download_url'];
                                         //add arguments array
                                         $add_arguments = array('item_id' => $item_id);
                                         //PDF Download URL
                                         $download_url = add_query_arg($add_arguments, $download_url);
                                         //get product name
                                         $product_name = isset($_product->post->post_title) ? $_product->post->post_title : '';
                                         //Download file arguments
                                         $download_args = array('download_url' => $download_url, 'download_name' => $product_name . ' - ' . $download_file['name'] . ' ' . $voucher_number . ' ( ' . $order_date . ' )', 'downloads_remaining' => '');
                                         //append voucher download to downloads array
                                         $downloads[] = $download_args;
                                     }
                                 }
                             }
                         }
                     }
                     //reset global order ID
                     $vou_order = 0;
                 }
             }
         }
     }
     return $downloads;
 }