</tfoot>
	<tbody>
		<?php 
if (sizeof($order->get_items()) > 0) {
    foreach ($order->get_items() as $item) {
        if (isset($item['variation_id']) && $item['variation_id'] > 0) {
            $_product = new WC_Product_Variation($item['variation_id']);
        } else {
            $_product = new WC_Product($item['id']);
        }
        echo '
					<tr>
						<td class="product-name">';
        echo '<a href="' . get_permalink($item['id']) . '">' . $item['name'] . '</a>';
        $item_meta = new order_item_meta($item['item_meta']);
        $item_meta->display();
        if ($_product->exists && $_product->is_downloadable() && ($order->status == 'completed' || get_option('woocommerce_downloads_grant_access_after_payment') == 'yes' && $order->status == 'processing')) {
            echo '<br/><small><a href="' . $order->get_downloadable_file_url($item['id'], $item['variation_id']) . '">' . __('Download file &rarr;', 'woocommerce') . '</a></small>';
        }
        echo '</td><td class="product-quantity">' . $item['qty'] . '</td><td class="product-total">' . $order->get_formatted_line_subtotal($item) . '</td></tr>';
        // Show any purchase notes
        if ($order->status == 'completed' || $order->status == 'processing') {
            if ($purchase_note = get_post_meta($_product->id, '_purchase_note', true)) {
                echo '<tr class="product-purchase-note"><td colspan="3">' . apply_filters('the_content', $purchase_note) . '</td></tr>';
            }
        }
    }
}
do_action('woocommerce_order_items_table', $order);
?>
	</tbody>
    /** Output items for display in html emails */
    function email_order_items_table($show_download_links = false, $show_sku = false)
    {
        $return = '';
        foreach ($this->get_items() as $item) {
            $_product = $this->get_product_from_item($item);
            $file = $sku = $variation = '';
            if ($show_sku && $_product->get_sku()) {
                $sku = ' (#' . $_product->get_sku() . ')';
            }
            $item_meta = new order_item_meta($item['item_meta']);
            $variation = '<br/><small>' . $item_meta->display(true, true) . '</small>';
            if ($show_download_links) {
                if ($_product->exists) {
                    if ($_product->is_downloadable()) {
                        $file = '<br/><small>' . __('Download:', 'woocommerce') . ' <a href="' . $this->get_downloadable_file_url($item['id'], $item['variation_id']) . '">' . $this->get_downloadable_file_url($item['id'], $item['variation_id']) . '</a></small>';
                    }
                }
            }
            $return .= '<tr>
				<td style="text-align:left; border: 1px solid #eee;">' . apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $sku . $file . $variation . '</td>
				<td style="text-align:left; border: 1px solid #eee;">' . $item['qty'] . '</td>
				<td style="text-align:left; border: 1px solid #eee;">';
            if ($this->display_cart_ex_tax || !$this->prices_include_tax) {
                $ex_tax_label = $this->prices_include_tax ? 1 : 0;
                $return .= woocommerce_price($this->get_line_subtotal($item), array('ex_tax_label' => $ex_tax_label));
            } else {
                $return .= woocommerce_price($this->get_line_subtotal($item, true));
            }
            $return .= '	
				</td>
			</tr>';
        }
        $return = apply_filters('woocommerce_email_order_items_table', $return);
        return $return;
    }
 /**
  * Get PayPal Args for passing to PP
  **/
 function get_paypal_args($order)
 {
     global $woocommerce;
     $order_id = $order->id;
     if ($this->debug == 'yes') {
         $this->log->add('paypal', 'Generating payment form for order #' . $order_id . '. Notify URL: ' . trailingslashit(home_url()) . '?paypalListener=paypal_standard_IPN');
     }
     if (in_array($order->billing_country, array('US', 'CA'))) {
         $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone);
         $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
     } else {
         $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
     }
     // PayPal Args
     $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->email, 'no_note' => 1, 'currency_code' => get_option('woocommerce_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => $this->get_return_url($order), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => trailingslashit(home_url()) . '?paypalListener=paypal_standard_IPN', 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->order_key), $phone_args);
     // Shipping
     if ($this->send_shipping == 'yes') {
         $paypal_args['no_shipping'] = 0;
         $paypal_args['address_override'] = 1;
         // If we are sending shipping, send shipping address instead of billing
         $paypal_args['first_name'] = $order->shipping_first_name;
         $paypal_args['last_name'] = $order->shipping_last_name;
         $paypal_args['company'] = $order->shipping_company;
         $paypal_args['address1'] = $order->shipping_address_1;
         $paypal_args['address2'] = $order->shipping_address_2;
         $paypal_args['city'] = $order->shipping_city;
         $paypal_args['state'] = $order->shipping_state;
         $paypal_args['country'] = $order->shipping_country;
         $paypal_args['zip'] = $order->shipping_postcode;
     } else {
         $paypal_args['no_shipping'] = 1;
     }
     // If prices include tax or have order discounts, send the whole order
     if (get_option('woocommerce_prices_include_tax') == 'yes' || $order->get_order_discount() > 0) {
         // Discount
         $paypal_args['discount_amount_cart'] = $order->get_order_discount();
         // Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall
         $item_names = array();
         if (sizeof($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_names[] = $item['name'] . ' x ' . $item['qty'];
                 }
             }
         }
         $paypal_args['item_name_1'] = sprintf(__('Order #%s', 'woocommerce'), $order->id) . " - " . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->get_order_total() - $order->get_shipping() + $order->get_order_discount(), 2, '.', '');
         // Shipping Cost
         if ($order->get_shipping() > 0) {
             $paypal_args['item_name_2'] = __('Shipping via', 'woocommerce') . ucwords($order->shipping_method_title);
             $paypal_args['quantity_2'] = '1';
             $paypal_args['amount_2'] = number_format($order->get_shipping(), 2, '.', '');
         }
     } else {
         // Tax
         $paypal_args['tax_cart'] = $order->get_total_tax();
         // Cart Contents
         $item_loop = 0;
         if (sizeof($order->get_items()) > 0) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_loop++;
                     $product = $order->get_product_from_item($item);
                     $item_name = $item['name'];
                     $item_meta = new order_item_meta($item['item_meta']);
                     if ($meta = $item_meta->display(true, true)) {
                         $item_name .= ' (' . $meta . ')';
                     }
                     $paypal_args['item_name_' . $item_loop] = $item_name;
                     if ($product->get_sku()) {
                         $paypal_args['item_number_' . $item_loop] = $product->get_sku();
                     }
                     $paypal_args['quantity_' . $item_loop] = $item['qty'];
                     $paypal_args['amount_' . $item_loop] = $order->get_item_total($item, false);
                 }
             }
         }
         // Shipping Cost
         if ($order->get_shipping() > 0) {
             $item_loop++;
             $paypal_args['item_name_' . $item_loop] = __('Shipping via', 'woocommerce') . ucwords($order->shipping_method_title);
             $paypal_args['quantity_' . $item_loop] = '1';
             $paypal_args['amount_' . $item_loop] = number_format($order->get_shipping(), 2, '.', '');
         }
     }
     $paypal_args = apply_filters('woocommerce_paypal_args', $paypal_args);
     return $paypal_args;
 }
    $_product = $order->get_product_from_item($item);
    $item_meta = new order_item_meta($item['item_meta']);
    $image = $show_image ? '<img src="' . current(wp_get_attachment_image_src(get_post_thumbnail_id($_product->id), 'thumbnail')) . '" alt="Product Image" height="' . $image_size[1] . '" width="' . $image_size[0] . '" style="vertical-align:middle; margin-right: 10px;" />' : '';
    ?>
	<tr>
		<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php 
    // Show title/image etc
    echo apply_filters('woocommerce_order_product_image', $image, $_product, $show_image);
    // Product name
    echo apply_filters('woocommerce_order_product_title', $item['name'], $_product);
    // SKU
    echo $show_sku && $_product->get_sku() ? ' (#' . $_product->get_sku() . ')' : '';
    // File URL
    echo $show_download_links && $_product->exists() && $_product->is_downloadable() ? '<br/><small>' . __('Download:', 'woocommerce') . ' <a href="' . $order->get_downloadable_file_url($item['id'], $item['variation_id']) . '" target="_blank">' . $order->get_downloadable_file_url($item['id'], $item['variation_id']) . '</a></small>' : '';
    // Variation
    echo $item_meta->meta ? '<br/><small>' . $item_meta->display(true, true) . '</small>' : '';
    ?>
</td>
		<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php 
    echo $item['qty'];
    ?>
</td>
		<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><?php 
    echo $order->get_formatted_line_subtotal($item);
    ?>
</td>
	</tr>
	
	<?php 
    if ($show_purchase_note && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
        ?>
    /**
     * Generate the paypal button link
     **/
    public function generate_paypal_form($order_id)
    {
        global $woocommerce;
        $order = new WC_Order($order_id);
        if ($this->testmode == 'yes') {
            $paypal_adr = $this->testurl . '?test_ipn=1&';
        } else {
            $paypal_adr = $this->liveurl . '?';
        }
        if ($this->debug == 'yes') {
            $this->log->add('paypal', 'Generating payment form for order #' . $order_id . '. Notify URL: ' . trailingslashit(home_url()) . '?paypalListener=paypal_standard_IPN');
        }
        if (in_array($order->billing_country, array('US', 'CA'))) {
            $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone);
            $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
        } else {
            $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
        }
        // PayPal Args
        $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->email, 'no_note' => 1, 'currency_code' => get_option('woocommerce_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => $this->get_return_url($order), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => trailingslashit(home_url()) . '?paypalListener=paypal_standard_IPN', 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->order_key), $phone_args);
        // Shipping
        if ($this->send_shipping == 'yes') {
            $paypal_args['no_shipping'] = 0;
            $paypal_args['address_override'] = 1;
            // If we are sending shipping, send shipping address instead of billing
            $paypal_args['first_name'] = $order->shipping_first_name;
            $paypal_args['last_name'] = $order->shipping_last_name;
            $paypal_args['company'] = $order->shipping_company;
            $paypal_args['address1'] = $order->shipping_address_1;
            $paypal_args['address2'] = $order->shipping_address_2;
            $paypal_args['city'] = $order->shipping_city;
            $paypal_args['state'] = $order->shipping_state;
            $paypal_args['zip'] = $order->shipping_postcode;
            $paypal_args['country'] = $order->shipping_country;
        } else {
            $paypal_args['no_shipping'] = 1;
        }
        // If prices include tax or have order discounts, send the whole order
        if (get_option('woocommerce_prices_include_tax') == 'yes' || $order->get_order_discount() > 0) {
            // Discount
            $paypal_args['discount_amount_cart'] = $order->get_order_discount();
            // Don't pass items - paypal borks tax due to prices including tax. PayPal has no option for tax inclusive pricing sadly. Pass 1 item for the order items overall
            $paypal_args['item_name_1'] = sprintf(__('Order #%s', 'woocommerce'), $order->id);
            $paypal_args['quantity_1'] = 1;
            $paypal_args['amount_1'] = number_format($order->get_order_total() - $order->get_shipping() + $order->get_order_discount(), 2, '.', '');
            // Shipping Cost
            if ($order->get_shipping() > 0) {
                $paypal_args['item_name_2'] = __('Shipping via ', 'woocommerce') . ucwords($order->shipping_method_title);
                $paypal_args['quantity_2'] = '1';
                $paypal_args['amount_2'] = number_format($order->get_shipping(), 2, '.', '');
            }
        } else {
            // Tax
            $paypal_args['tax_cart'] = $order->get_total_tax();
            // Cart Contents
            $item_loop = 0;
            if (sizeof($order->get_items()) > 0) {
                foreach ($order->get_items() as $item) {
                    if ($item['qty']) {
                        $item_loop++;
                        $product = $order->get_product_from_item($item);
                        $item_name = $item['name'];
                        if (get_option('woocommerce_enable_sku') == 'yes' && $product->get_sku()) {
                            $item_name .= ' (' . $product->get_sku() . ')';
                        }
                        $item_meta = new order_item_meta($item['item_meta']);
                        if ($meta = $item_meta->display(true, true)) {
                            $item_name .= ' (' . $meta . ')';
                        }
                        $paypal_args['item_name_' . $item_loop] = $item_name;
                        $paypal_args['quantity_' . $item_loop] = $item['qty'];
                        $paypal_args['amount_' . $item_loop] = $order->get_item_total($item, false);
                    }
                }
            }
            // Shipping Cost
            if ($order->get_shipping() > 0) {
                $item_loop++;
                $paypal_args['item_name_' . $item_loop] = __('Shipping via ', 'woocommerce') . ucwords($order->shipping_method_title);
                $paypal_args['quantity_' . $item_loop] = '1';
                $paypal_args['amount_' . $item_loop] = number_format($order->get_shipping(), 2, '.', '');
            }
        }
        $paypal_args = apply_filters('woocommerce_paypal_args', $paypal_args);
        $paypal_args_array = array();
        foreach ($paypal_args as $key => $value) {
            $paypal_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
        }
        $woocommerce->add_inline_js('
			jQuery("body").block({ 
					message: "<img src=\\"' . esc_url($woocommerce->plugin_url()) . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting...\\" style=\\"float:left; margin-right: 10px;\\" />' . __('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woocommerce') . '", 
					overlayCSS: 
					{ 
						background: "#fff", 
						opacity: 0.6 
					},
					css: { 
				        padding:        20, 
				        textAlign:      "center", 
				        color:          "#555", 
				        border:         "3px solid #aaa", 
				        backgroundColor:"#fff", 
				        cursor:         "wait",
				        lineHeight:		"32px"
				    } 
				});
			jQuery("#submit_paypal_payment_form").click();
		');
        return '<form action="' . esc_url($paypal_adr) . '" method="post" id="paypal_payment_form">
				' . implode('', $paypal_args_array) . '
				<input type="submit" class="button-alt" id="submit_paypal_payment_form" value="' . __('Pay via PayPal', 'woocommerce') . '" /> <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel order &amp; restore cart', 'woocommerce') . '</a>
			</form>';
    }
    /** Output items for display in html emails */
    function email_order_items_table($show_download_links = false, $show_sku = false, $show_purchase_note = false, $show_image = false, $image_size = array(32, 32))
    {
        $return = '';
        foreach ($this->get_items() as $item) {
            $_product = $this->get_product_from_item($item);
            $file = $sku = $variation = $image = '';
            if ($show_image) {
                $src = wp_get_attachment_image_src(get_post_thumbnail_id($_product->id), 'thumbnail');
                $image = apply_filters('woocommerce_order_product_image', '<img src="' . $src[0] . '" alt="Product Image" height="' . $image_size[1] . '" width="' . $image_size[0] . '" style="vertical-align:middle; margin-right: 10px;" />', $_product);
            }
            if ($show_sku && $_product->get_sku()) {
                $sku = ' (#' . $_product->get_sku() . ')';
            }
            $item_meta = new order_item_meta($item['item_meta']);
            $variation = '<br/><small>' . $item_meta->display(true, true) . '</small>';
            if ($show_download_links) {
                if ($_product->exists) {
                    if ($_product->is_downloadable()) {
                        $file = '<br/><small>' . __('Download:', 'woocommerce') . ' <a href="' . $this->get_downloadable_file_url($item['id'], $item['variation_id']) . '">' . $this->get_downloadable_file_url($item['id'], $item['variation_id']) . '</a></small>';
                    }
                }
            }
            $return .= '<tr>
				<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $image . apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $sku . $file . $variation . '</td>
				<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $item['qty'] . '</td>
				<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">';
            if ($this->display_cart_ex_tax || !$this->prices_include_tax) {
                $ex_tax_label = $this->prices_include_tax ? 1 : 0;
                $return .= woocommerce_price($this->get_line_subtotal($item), array('ex_tax_label' => $ex_tax_label));
            } else {
                $return .= woocommerce_price($this->get_line_subtotal($item, true));
            }
            $return .= '	
				</td>
			</tr>';
            // Show any purchase notes
            if ($show_purchase_note) {
                if ($purchase_note = get_post_meta($_product->id, '_purchase_note', true)) {
                    $return .= '<tr><td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . apply_filters('the_content', $purchase_note) . '</td></tr>';
                }
            }
        }
        $return = apply_filters('woocommerce_email_order_items_table', $return);
        return $return;
    }