display() публичный Метод

Display meta in a formatted list.
public display ( boolean $flat = false, boolean $return = false, string $hideprefix = '_', string $delimiter = ", " ) : string | void
$flat boolean (default: false)
$return boolean (default: false)
$hideprefix string (default: _)
$delimiter string Delimiter used to separate items when $flat is true
Результат string | void
Пример #1
0
function siw_wc_email_show_project_details($order, $application_number)
{
    ?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<?php 
    siw_wc_generate_email_table_header_row('Aanmelding');
    siw_wc_generate_email_table_row('Aanmeldnummer', $application_number);
    foreach ($order->get_items() as $item_id => $item) {
        $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
        $item_meta = new WC_Order_Item_Meta($item, $_product);
        //projectdetails formatteren
        $item_details = apply_filters('woocommerce_order_item_name', $item['name'], $item) . ' (' . get_post_meta($_product->id, 'projectduur', true) . ')';
        if ($item_meta->meta) {
            $item_details .= '<br/><small>' . nl2br($item_meta->display(true, true, '_', "\n")) . '</small>';
        }
        siw_wc_generate_email_table_row('Project', $item_details);
    }
    $discount = $order->get_total_discount();
    $subtotal = $order->get_subtotal();
    $total = $order->get_total();
    //subtotaal alleen tonen als het afwijkt van het totaal
    if ($subtotal != $total) {
        siw_wc_generate_email_table_row('Subtotaal', $order->get_subtotal_to_display());
        siw_wc_generate_email_table_row('Korting', '-' . $order->get_discount_to_display());
    }
    siw_wc_generate_email_table_row('Totaal', $order->get_formatted_order_total());
    siw_wc_generate_email_table_row('Betaalwijze', $order->payment_method_title);
    ?>
	
	</table>
	<?php 
}
 /**
  * Get order items.
  *
  * @param  WC_Order $order Order data.
  *
  * @return array           Items list, extra amount and shipping cost.
  */
 protected function get_order_items($order)
 {
     $items = array();
     $extra_amount = 0;
     $shipping_cost = 0;
     // Force only one item.
     if ('yes' == $this->gateway->send_only_total) {
         $items[] = array('description' => $this->sanitize_description(sprintf(__('Order %s', 'woocommerce-pagseguro'), $order->get_order_number())), 'amount' => $this->money_format($order->get_total()), 'quantity' => 1);
     } else {
         // Products.
         if (0 < count($order->get_items())) {
             foreach ($order->get_items() as $order_item) {
                 if ($order_item['qty']) {
                     $item_name = $order_item['name'];
                     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.4.0', '<')) {
                         $item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
                     } else {
                         $item_meta = new WC_Order_Item_Meta($order_item);
                     }
                     if ($meta = $item_meta->display(true, true)) {
                         $item_name .= ' - ' . $meta;
                     }
                     $items[] = array('description' => $this->sanitize_description($item_name), 'amount' => $this->money_format($order->get_item_total($order_item, false)), 'quantity' => $order_item['qty']);
                 }
             }
         }
         // Fees.
         if (0 < count($order->get_fees())) {
             foreach ($order->get_fees() as $fee) {
                 $items[] = array('description' => $this->sanitize_description($fee['name']), 'amount' => $this->money_format($fee['line_total']), 'quantity' => 1);
             }
         }
         // Taxes.
         if (0 < count($order->get_taxes())) {
             foreach ($order->get_taxes() as $tax) {
                 $items[] = array('description' => $this->sanitize_description($tax['label']), 'amount' => $this->money_format($tax['tax_amount'] + $tax['shipping_tax_amount']), 'quantity' => 1);
             }
         }
         // Shipping Cost.
         if (0 < $order->get_total_shipping()) {
             $shipping_cost = $this->money_format($order->get_total_shipping());
         }
         // Discount.
         if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.3', '<')) {
             if (0 < $order->get_order_discount()) {
                 $extra_amount = '-' . $this->money_format($order->get_order_discount());
             }
         }
     }
     return array('items' => $items, 'extra_amount' => $extra_amount, 'shipping_cost' => $shipping_cost);
 }
 /**
  * Display meta data belonging to an item
  * @param  array $item
  */
 public function display_item_meta($item)
 {
     $product = $this->get_product_from_item($item);
     $item_meta = new WC_Order_Item_Meta($item, $product);
     $item_meta->display();
 }
        if (WC_Subscriptions::is_woocommerce_pre('2.4')) {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item['item_meta'], $product);
            ?>
					<?php 
        } else {
            ?>
						<?php 
            $item_meta = new WC_Order_Item_Meta($order_item, $product);
            ?>
					<?php 
        }
        ?>
					<?php 
        $meta_to_display = $item_meta->display(true, true);
        ?>
					<?php 
        if (!empty($meta_to_display)) {
            ?>
					<p>
					<?php 
            echo $meta_to_display;
            ?>
					</p>
					<?php 
        }
        ?>
				</td>
				<td class="subscription-status" style="text-align:left; white-space:nowrap;" data-title="<?php 
        _e('Status', 'woocommerce-subscriptions');
                ?>
										<?php 
            }
            if ($i != 0) {
                echo "<span>Y</span>";
            } else {
                echo "<span>N</span>";
            }
            ?>
										</small>
										<?php 
        }
        //Added New For Add Location End
        // Variation
        if ($item_meta->meta) {
            echo '<br/><small>' . nl2br($item_meta->display(true, true, '_', "\n")) . '</small>';
        }
        // File URLs
        if ($show_download_links && is_object($_product) && $_product->exists() && $_product->is_downloadable()) {
            $download_files = $order->get_item_downloads($item);
            $i = 0;
            foreach ($download_files as $download_id => $file) {
                $i++;
                if (count($download_files) > 1) {
                    $prefix = sprintf(__('Download %d', 'woocommerce'), $i);
                } elseif ($i == 1) {
                    $prefix = __('Download', 'woocommerce');
                }
                echo '<br/><small>' . $prefix . ': <a href="' . esc_url($file['download_url']) . '" target="_blank">' . esc_html($file['name']) . '</a></small>';
            }
        }
 /**
  * Get the invoice line items for a given order. This includes:
  *
  * + Products, mapped as FreshBooks items when the admin has linked them
  * + Fees, mapped as a `Fee` item
  * + Shipping, mapped as a `Shipping` item
  * + Taxes, mapped using the tax code as the item
  *
  * Note that taxes cannot be added per-product as WooCommerce doesn't provide
  * any way to get individual tax information per product and FreshBooks requires
  * a tax name/percentage to be set on a per-product basis. Further, FreshBooks
  * only allows 2 taxes per product where realistically most stores will have
  * more
  *
  * @param \WC_FreshBooks_Order $order order instance
  * @return array line items
  * @since 3.0
  */
 private function get_invoice_lines(WC_FreshBooks_Order $order)
 {
     $line_items = array();
     // add products
     foreach ($order->get_items() as $item_key => $item) {
         $product = $order->get_product_from_item($item);
         // must be a valid product
         if (is_object($product)) {
             $product_id = $product->is_type('variation') ? $product->variation_id : $product->id;
             $item_name = metadata_exists('post', $product_id, '_wc_freshbooks_item_name') ? get_post_meta($product_id, '_wc_freshbooks_item_name', true) : $product->get_sku();
             $item_meta = new WC_Order_Item_Meta(SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta']);
             // variation data, item meta, etc
             $meta = $item_meta->display(true, true);
             // grouped products include a &arr; in the name which must be converted back to an arrow
             $item_description = html_entity_decode($product->get_title(), ENT_QUOTES, 'UTF-8') . ($meta ? sprintf(' (%s)', $meta) : '');
         } else {
             $item_name = __('Product', WC_FreshBooks::TEXT_DOMAIN);
             $item_description = $item['name'];
         }
         $line_items[] = array('name' => $item_name, 'description' => apply_filters('wc_freshbooks_line_item_description', $item_description, $item, $order, $item_key), 'unit_cost' => $order->get_item_subtotal($item), 'quantity' => $item['qty']);
     }
     $coupons = $order->get_items('coupon');
     // add coupons
     foreach ($coupons as $coupon_item) {
         $coupon = new WC_Coupon($coupon_item['name']);
         $coupon_post = get_post($coupon->id);
         $coupon_type = false !== strpos($coupon->type, '_cart') ? __('Cart Discount', WC_FreshBooks::TEXT_DOMAIN) : __('Product Discount', WC_FreshBooks::TEXT_DOMAIN);
         $line_items[] = array('name' => $coupon_item['name'], 'description' => is_object($coupon_post) && $coupon_post->post_excerpt ? sprintf(__('%s - %s', WC_FreshBooks::TEXT_DOMAIN), $coupon_type, $coupon_post->post_excerpt) : $coupon_type, 'unit_cost' => wc_format_decimal($coupon_item['discount_amount'] * -1, 2), 'quantity' => 1);
     }
     // manually created orders can't have coupon items, but may have an order discount set
     // which must be added as a line item
     if (0 == count($coupons) && $order->get_total_discount() > 0) {
         $line_items[] = array('name' => __('Order Discount', WC_FreshBooks::TEXT_DOMAIN), 'description' => __('Order Discount', WC_FreshBooks::TEXT_DOMAIN), 'unit_cost' => wc_format_decimal($order->get_total_discount() * -1, 2), 'quantity' => 1);
     }
     // add fees
     foreach ($order->get_fees() as $fee_key => $fee) {
         $line_items[] = array('name' => __('Fee', WC_FreshBooks::TEXT_DOMAIN), 'description' => $fee['name'], 'unit_cost' => $order->get_line_total($fee), 'quantity' => 1);
     }
     // add shipping
     foreach ($order->get_shipping_methods() as $shipping_method_key => $shipping_method) {
         $line_items[] = array('name' => __('Shipping', WC_FreshBooks::TEXT_DOMAIN), 'description' => ucwords(str_replace('_', ' ', $shipping_method['method_id'])), 'unit_cost' => $shipping_method['cost'], 'quantity' => 1);
     }
     // add taxes
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $line_items[] = array('name' => $tax_code, 'description' => $tax->label, 'unit_cost' => number_Format($tax->amount, 2, '.', ''), 'quantity' => 1);
     }
     return $line_items;
 }
 /**
  * Get order item names as a string
  * @param  WC_Order $order
  * @param  array $item
  * @return string
  */
 protected function get_order_item_name($order, $item)
 {
     $item_name = $item['name'];
     $item_meta = new WC_Order_Item_Meta($item);
     if ($meta = $item_meta->display(true, true)) {
         $item_name .= ' ( ' . $meta . ' )';
     }
     return $item_name;
 }
 /**
  * plain_vendor_order_item_table function to get the plain html of item table of a vendor.
  * @access public
  * @param order id , vendor term id 
  */
 public function plain_vendor_order_item_table($order, $vendor_id, $is_ship = false)
 {
     global $WCMp;
     require_once 'class-wcmp-calculate-commission.php';
     $commission_obj = new WCMp_Calculate_Commission();
     $vendor_items = $this->get_vendor_items_from_order($order->id, $vendor_id);
     foreach ($vendor_items as $item_id => $item) {
         $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
         $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
         // Title
         echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
         // Variation
         echo $item_meta->meta ? "\n" . $item_meta->display(true, true) : '';
         // Quantity
         echo "\n" . sprintf(__('Quantity: %s', $WCMp->text_domain), $item['qty']);
         if (isset($item['variation_id']) && !empty($item['variation_id'])) {
             $variation_id = $item['variation_id'];
         }
         $product_id = $item['product_id'];
         if ($is_ship) {
             echo "\n" . sprintf(__('Total: %s', $WCMp->text_domain), $order->get_formatted_line_subtotal($item));
         } else {
             echo "\n" . sprintf(__('Commission: %s', $WCMp->text_domain), $commission_obj->get_item_commission($product_id, $variation_id, $item, $order->id, $item_id));
         }
         echo "\n\n";
     }
 }
 /**
  * ConfirmPayment
  *
  * Finalizes the checkout with PayPal's DoExpressCheckoutPayment API
  *
  * @FinalPaymentAmt (double) Final payment amount for the order.
  */
 function ConfirmPayment($FinalPaymentAmt)
 {
     /*
      * Display message to user if session has expired.
      */
     if (sizeof(WC()->cart->get_cart()) == 0) {
         $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage &rarr;</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"');
         $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms);
         wc_add_notice($ec_confirm_message, "error");
     }
     /*
      * Check if the PayPal class has already been established.
      */
     if (!class_exists('Angelleye_PayPal')) {
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php';
     }
     /*
      * Create PayPal object.
      */
     $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature);
     $PayPal = new Angelleye_PayPal($PayPalConfig);
     /*
      * Get data from WooCommerce object
      */
     if (!empty($this->confirm_order_id)) {
         $order = new WC_Order($this->confirm_order_id);
         $invoice_number = preg_replace("/[^0-9]/", "", $order->get_order_number());
         if ($order->customer_note) {
             $customer_notes = wptexturize($order->customer_note);
         }
         $shipping_first_name = $order->shipping_first_name;
         $shipping_last_name = $order->shipping_last_name;
         $shipping_address_1 = $order->shipping_address_1;
         $shipping_address_2 = $order->shipping_address_2;
         $shipping_city = $order->shipping_city;
         $shipping_state = $order->shipping_state;
         $shipping_postcode = $order->shipping_postcode;
         $shipping_country = $order->shipping_country;
     }
     // Prepare request arrays
     $DECPFields = array('token' => urlencode($this->get_session('TOKEN')), 'payerid' => urlencode($this->get_session('payer_id')), 'returnfmfdetails' => '', 'giftmessage' => $this->get_session('giftmessage'), 'giftreceiptenable' => $this->get_session('giftreceiptenable'), 'giftwrapname' => $this->get_session('giftwrapname'), 'giftwrapamount' => $this->get_session('giftwrapamount'), 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => '');
     $Payments = array();
     $order_items_own = array();
     $final_order_total = $order->get_order_item_totals();
     $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency());
     $final_order_total_amt_strip_ec = strip_tags($final_order_total['order_total']['value']);
     $final_order_total_amt_strip = str_replace(',', '', $final_order_total_amt_strip_ec);
     $final_order_total_amt = str_replace($current_currency, '', $final_order_total_amt_strip);
     $Payment = array('amt' => number_format($final_order_total_amt, 2, '.', ''), 'currencycode' => get_woocommerce_currency(), 'shippingdiscamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'desc' => '', 'custom' => '', 'invnum' => preg_replace("/[^0-9]/", "", $this->confirm_order_id), 'notifyurl' => '', 'shiptoname' => $shipping_first_name . ' ' . $shipping_last_name, 'shiptostreet' => $shipping_address_1, 'shiptostreet2' => $shipping_address_2, 'shiptocity' => $shipping_city, 'shiptostate' => $shipping_state, 'shiptozip' => $shipping_postcode, 'shiptocountrycode' => $shipping_country, 'shiptophonenum' => '', 'notetext' => $this->get_session('customer_notes'), 'allowedpaymentmethod' => '', 'paymentaction' => $this->payment_action == 'Authorization' ? 'Authorization' : 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '', 'sellerid' => '', 'sellerusername' => '', 'sellerregistrationdate' => '', 'softdescriptor' => '');
     $PaymentOrderItems = array();
     $ctr = $total_items = $total_discount = $total_tax = $shipping = 0;
     $ITEMAMT = 0;
     $counter = 1;
     if (sizeof($order->get_items()) > 0) {
         //   if ($this->send_items) {
         foreach ($order->get_items() as $values) {
             $_product = $order->get_product_from_item($values);
             $qty = absint($values['qty']);
             $sku = $_product->get_sku();
             $values['name'] = html_entity_decode($values['name'], ENT_NOQUOTES, 'UTF-8');
             if ($_product->product_type == 'variation') {
                 if (empty($sku)) {
                     $sku = $_product->parent->get_sku();
                 }
                 //$item_meta = new WC_Order_Item_Meta($values['item_meta']);
                 $item_meta = new WC_Order_Item_Meta($values, $_product);
                 $meta = $item_meta->display(true, true);
                 if (!empty($meta)) {
                     $values['name'] .= " - " . str_replace(", \n", " - ", $meta);
                 }
             }
             //////////////////////////////////////////***************************////////////////////////////////////
             $lineitems_prepare = $this->prepare_line_items($order);
             $lineitems = $_SESSION['line_item'];
             if (in_array($values['product_id'], $lineitems)) {
                 $arraykey = array_search($values['product_id'], $lineitems);
                 $item_position = str_replace('product_number_', '', $arraykey);
                 $get_amountkey = 'amount_' . $counter;
                 $get_qtykey = 'quantity_' . $counter;
                 $switcher_amt = $lineitems[$get_amountkey];
                 $switcher_qty = $lineitems[$get_qtykey];
                 $counter = $counter + 1;
             }
             //////////////////////////////////////////***************************////////////////////////////////////
             $Item = array('name' => $values['name'], 'desc' => '', 'amt' => round($switcher_amt, 2), 'number' => $sku, 'qty' => $qty, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
             array_push($PaymentOrderItems, $Item);
             $ITEMAMT += round($switcher_amt, 2) * $switcher_qty;
             $order_items_own[] = round($switcher_amt, 2) * $switcher_qty;
         }
         /**
          * Add custom Woo cart fees as line items
          */
         foreach (WC()->cart->get_fees() as $fee) {
             $Item = array('name' => $fee->name, 'desc' => '', 'amt' => number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
             /**
              * The gift wrap amount actually has its own parameter in
              * DECP, so we don't want to include it as one of the line
              * items.
              */
             if ($Item['number'] != 'gift-wrap') {
                 array_push($PaymentOrderItems, $Item);
                 $ITEMAMT += $fee->amount * $Item['qty'];
                 $order_items_own[] = $fee->amount * $Item['qty'];
             }
             $ctr++;
         }
         if (!$this->is_wc_version_greater_2_3()) {
             /*
              * Get discounts
              */
             if ($order->get_order_discount() > 0) {
                 // foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                 $Item = array('name' => 'Cart Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format(WC()->cart->coupon_discount_amounts[$code], 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 //}
                 $total_discount -= $order->get_cart_discount();
                 $order_items_own[] = $fee->amount * $Item['qty'];
             }
             if ($order->get_order_discount() > 0) {
                 //  foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                 $Item = array('name' => 'Order Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format($order->get_order_discount(), 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 //  }
                 $total_discount -= $order->get_order_discount();
                 $order_items_own[] = round($total_discount, 2);
             }
         } else {
             if ($order->get_total_discount() > 0) {
                 $Item = array('name' => 'Total Discount', 'qty' => 1, 'amt' => -number_format($order->get_total_discount(), 2, '.', ''));
                 array_push($PaymentOrderItems, $Item);
                 $total_discount -= $order->get_total_discount();
                 $order_items_own[] = round($total_discount, 2);
             }
         }
         //   } if(this->senditem)1876
         /*
          * Set shipping and tax values.
          */
         /*             * *****************************MD******************************** */
         foreach ($order->get_tax_totals() as $code => $tax) {
             $tax_string_array[] = $tax->formatted_amount;
         }
         $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency());
         if (isset($tax_string_array) && !empty($tax_string_array)) {
             $striped_amt = strip_tags($tax_string_array[0]);
             if (isset($striped_amt) && !empty($striped_amt)) {
                 $tot_tax = str_replace($current_currency, '', $striped_amt);
             }
         }
         /*             * ****************************MD******************************** */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = $order->get_total_shipping();
             //+ $order->get_shipping_tax();
             $tax = 0;
         } else {
             $shipping = $order->get_total_shipping();
             if (isset($tot_tax) && !empty($tot_tax)) {
                 $tax = $tot_tax;
             } else {
                 $tax = 0;
             }
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             if (isset($tot_tax) && !empty($tot_tax)) {
                 $tax = $tot_tax;
             } else {
                 $tax = 0;
             }
         }
         if ($tax > 0) {
             $tax = number_format($tot_tax, 2, '.', '');
         }
         if ($shipping > 0) {
             $shipping = number_format($shipping, 2, '.', '');
         }
         if ($total_discount) {
             $total_discount = round($total_discount, 2);
         }
         if ($this->send_items) {
             /*
              * Now that we have all items and subtotals
              * we can fill in necessary values.
              */
             $Payment['itemamt'] = number_format($ITEMAMT + $total_discount, 2, '.', '');
         } else {
             $PaymentOrderItems = array();
             $Payment['itemamt'] = number_format($ITEMAMT + $total_discount, 2, '.', '');
         }
         /*
          * Set tax
          */
         if ($tax > 0) {
             $Payment['taxamt'] = number_format($tot_tax, 2, '.', '');
             // Required if you specify itemized L_TAXAMT fields.  Sum of all tax items in this order.
         }
         /*
          * Set shipping
          */
         if ($shipping > 0) {
             $Payment['shippingamt'] = number_format($shipping, 2, '.', '');
             // Total shipping costs for this order.  If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
         }
     }
     $Payment['order_items'] = $PaymentOrderItems;
     array_push($Payments, $Payment);
     $UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
     $PayPalRequestData = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
     // Rounding amendment
     if (isset($tax) && !empty($tax)) {
         $tax = $tax;
     } else {
         $tax = '0.00';
     }
     if (isset($shipping) && !empty($shipping)) {
         $shipping = $shipping;
     } else {
         $shipping = '0.00';
     }
     if (trim(number_format($final_order_total_amt, 2, '.', '')) !== trim(number_format($Payment['itemamt'] + number_format($tax, 2, '.', '') + number_format($shipping, 2, '.', ''), 2, '.', ''))) {
         $diffrence_amount = $this->get_diffrent($final_order_total_amt, $Payment['itemamt'] + $tax + number_format($shipping, 2, '.', ''));
         if ($shipping > 0) {
             $PayPalRequestData['Payments'][0]['shippingamt'] = round($shipping + $diffrence_amount, 2);
         } elseif ($tax > 0) {
             $PayPalRequestData['Payments'][0]['taxamt'] = round($tax + $diffrence_amount, 2);
         } else {
             $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] + $diffrence_amount, 2);
         }
     }
     /* rounding amount */
     $order_item_total = 0;
     foreach ($order_items_own as $keypayment => $valuepayment) {
         $order_item_total = $order_item_total + $valuepayment;
     }
     if ($shipping <= 0 && $tax <= 0) {
         $diffrence_amount_rounded = $this->get_diffrent($final_order_total_amt, $order_item_total);
         $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] - $diffrence_amount_rounded, 2);
         $PayPalRequestData['Payments'][0]['amt'] = round($PayPalRequestData['Payments'][0]['amt'] - $diffrence_amount_rounded, 2);
     }
     // Pass data into class for processing with PayPal and load the response array into $PayPalResult
     $PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData);
     /*
      * Log API result
      */
     $this->add_log('Test Mode: ' . $this->testmode);
     $this->add_log('Endpoint: ' . $this->API_Endpoint);
     $PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : '';
     $PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : '';
     $this->add_log('Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true));
     $this->add_log('Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true));
     /*
      * Error handling
      */
     if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
         $this->remove_session('TOKEN');
         if (isset($_SESSION['line_item'])) {
             unset($_SESSION['line_item']);
         }
     }
     /*
      * Return the class library result array.
      */
     return $PayPalResult;
 }
 /**
  * Get products data.
  *
  * @param  WC_Order $order
  *
  * @return array
  */
 protected function get_products_data($order)
 {
     $i = 1;
     $data = array();
     // Force only one item.
     if ('yes' == $this->send_only_total || 'yes' == get_option('woocommerce_prices_include_tax')) {
         $data['cart_' . $i . '_name'] = $this->sanitize_string(sprintf(__('Order %s', 'woocommerce-checkout-cielo'), $order->get_order_number()));
         // $data['cart_' . $i . '_description'] = '';
         $data['cart_' . $i . '_unitprice'] = $this->get_price($order->get_total()) - $this->get_price($order->get_total_shipping()) + $this->get_discount($order);
         $data['cart_' . $i . '_quantity'] = '1';
         $data['cart_' . $i . '_type'] = '1';
         // $data['cart_' . $i . '_code']        = '';
         $data['cart_' . $i . '_weight'] = '0';
     } else {
         if (0 < sizeof($order->get_items())) {
             foreach ($order->get_items() as $order_item) {
                 if ($order_item['qty']) {
                     $item_total = $this->get_price($order->get_item_subtotal($order_item, false));
                     if (0 > $item_total) {
                         continue;
                     }
                     // Get product data.
                     $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($order_item), $order_item);
                     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.4.0', '<')) {
                         $item_meta = new WC_Order_Item_Meta($order_item['item_meta'], $_product);
                     } else {
                         $item_meta = new WC_Order_Item_Meta($order_item, $_product);
                     }
                     $data['cart_' . $i . '_name'] = $this->sanitize_string($order_item['name']);
                     if ($meta = $item_meta->display(true, true)) {
                         $data['cart_' . $i . '_description'] = $this->sanitize_string($meta, 256);
                     }
                     $data['cart_' . $i . '_unitprice'] = $item_total;
                     $data['cart_' . $i . '_quantity'] = $order_item['qty'];
                     $data['cart_' . $i . '_type'] = '1';
                     if ($sku = $_product->get_sku()) {
                         $data['cart_' . $i . '_code'] = $sku;
                     }
                     $data['cart_' . $i . '_weight'] = wc_get_weight($_product->get_weight(), 'g');
                     $i++;
                 }
             }
         }
         // Fees.
         if (0 < sizeof($order->get_fees())) {
             foreach ($order->get_fees() as $fee) {
                 $fee_total = $this->get_price($fee['line_total']);
                 if (0 > $fee_total) {
                     continue;
                 }
                 $data['cart_' . $i . '_name'] = $this->sanitize_string($fee['name']);
                 $data['cart_' . $i . '_unitprice'] = $fee_total;
                 $data['cart_' . $i . '_quantity'] = '1';
                 $data['cart_' . $i . '_type'] = '4';
                 $i++;
             }
         }
         // Taxes.
         if (0 < sizeof($order->get_taxes())) {
             foreach ($order->get_taxes() as $tax) {
                 $tax_total = $this->get_price($tax['tax_amount'] + $tax['shipping_tax_amount']);
                 if (0 > $tax_total) {
                     continue;
                 }
                 $data['cart_' . $i . '_name'] = $this->sanitize_string($tax['label']);
                 $data['cart_' . $i . '_unitprice'] = $tax_total;
                 $data['cart_' . $i . '_quantity'] = '1';
                 $data['cart_' . $i . '_type'] = '4';
                 $i++;
             }
         }
     }
     return $data;
 }
Пример #11
0
    function shortcode_altereports_func()
    {
        include_once ABSPATH . 'wp-admin/includes/plugin.php';
        include_once ABSPATH . WPINC . '/functions.php';
        global $wpdb, $woocommerce, $WC_Order, $woo_options, $WC_API_Reports, $WC_Admin_Dashboard, $WC_Admin_Reports, $WC_Admin_Report, $WC_Report_Customers, $WC_Report_Stock, $WC_alterinventory;
        $results = $wpdb->get_results('SELECT * FROM wp_options WHERE option_id = 1', OBJECT);
        $out = get_option('<h1 style="color:#F00">alterinventory_error_message</h1>', '<h1 style="color:#F00">Please use your Username and Password to Log In </h1>');
        $options = get_option('alterinventory_options');
        $user = wp_get_current_user();
        if (empty($user->ID)) {
            echo $out;
        }
        if (!is_user_logged_in()) {
            wp_login_form();
        } else {
            ?>
    <?php 
            /**
             * Template for Direct Sells
             */
            if (!defined('ABSPATH')) {
                exit;
            }
            global $wpdb, $Product, $item, $item_meta, $product, $woocommerce, $woo_options, $order_count, $WC_API_Reports, $WC_Admin_Dashboard, $WC_Admin_Reports, $WC_Admin_Report, $WC_Report_Customers, $WC_Report_Stock, $WC_alterinventory;
            $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array('numberposts' => $order_count, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => -1, 'paged' => get_query_var('paged'))));
            if ($customer_orders) {
                ?>
<div align="right" style="margin-bottom:-60px" >
<script type="text/javascript">
 function printPage(){
        var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
        var data = '<button onclick="window.print()"> Print </button>'+tableData;
        myWindow=window.open('','','width=1000,height=800px');
        myWindow.innerWidth = screen.width;
        myWindow.innerHeight = screen.height;
        myWindow.screenX = 0;
        myWindow.screenY = 0;
        myWindow.document.write(data);
        myWindow.focus();
    };
 </script>

 <br />
    <a href="javascript:void(0);" class="button" type="submit"  id="printPage" onclick="printPage();">Print</a>
    |
    <a href="alter-inventory/" class="button" type="submit" >
Aggiorna</a>
    <br />
    
    </div>
   
	
<div style="margin-bottom: 40px;" >
<?php 
                $form = '<form role="search" method="get" id="searchform" action="' . esc_url(home_url('/')) . '">
	<div>
		<label class="screen-reader-text" for="s">' . __('Cerca Vendite:', 'woocommerce') . '</label>
		<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __('Vendite..', 'woocommerce') . '" />
		<input class="button" type="submit" id="searchsubmit" value="' . esc_attr__('Search', 'woocommerce') . '" />
		<input type="hidden" name="post_type" value="product" />
	</div>
</form>';
                echo $form;
                ?>
</div>
<h2>VENDITE</h2>
   
	<table class="shop_table my_account_orders">

		<thead>
        
			<tr>
   
				<th class="order-number"><span class="nobr"><?php 
                _e('#ID Vendita', 'woocommerce');
                ?>
</span></th>
				<th class="order-date"><span class="nobr"><?php 
                _e('Data', 'woocommerce');
                ?>
</span></th>
				<th class="order-status"><span class="nobr"><?php 
                _e('Stato', 'woocommerce');
                ?>
</span></th>
				<th class="order-total"><span class="nobr"><?php 
                _e('Totale', 'woocommerce');
                ?>
</span></th>
                <th class="order-actions"><span class="nobr"><?php 
                _e('Prodotti / Attributi / Totale', 'woocommerce');
                ?>
</span></th>
				<th class="order-actions"><span class="nobr"><?php 
                _e('Dettagli', 'woocommerce');
                ?>
</span></th>
                <th class="order-actions"><span class="nobr"><?php 
                _e('Annullare', 'woocommerce');
                ?>
</span></th>
			</tr>
		</thead>

 <style>
								
								.hentry img { height: auto; max-width: 35%;}
								.woocommerce-message { display:none;}
						    </style>
		<tbody><?php 
                foreach ($customer_orders as $customer_order) {
                    $order = new WC_Order();
                    $order->populate($customer_order);
                    $status = get_term_by('slug', $order->status, 'shop_order_status');
                    $item_count = $order->get_item_count();
                    ?>
<tr class="order">
					<td class="order-number">
						<a href="<?php 
                    echo $order->get_view_order_url();
                    ?>
">
							<?php 
                    echo $order->get_order_number();
                    ?>
						</a>
					</td>
					<td class="order-date">
						<time datetime="<?php 
                    echo date('Y-m-d', strtotime($order->order_date));
                    ?>
" title="<?php 
                    echo esc_attr(strtotime($order->order_date));
                    ?>
"><?php 
                    echo date_i18n(get_option('date_format'), strtotime($order->order_date));
                    ?>
</time>
					</td>
					<td class="order-status" style="text-align:left; text-transform:uppercase; white-space:nowrap; color:#0C0"  >
						<?php 
                    echo ucfirst(__($status->name, 'woocommerce'));
                    ?>
					</td>
					<td class="order-total">
						<?php 
                    echo sprintf(_n('<strong>%s</strong> x <strong>%s Prodotto</strong>', '%s for %s items', $item_count, 'woocommerce'), $order->get_formatted_order_total(), $item_count);
                    ?>
					</td>
                   
		
                 <td class="order-actions">
  <table class="shop_table order_details">
	<thead>
		<tr>
			<th class="product-name"><?php 
                    _e('Product', 'woocommerce');
                    ?>
</th>
			<th class="product-total"><?php 
                    _e('Total', 'woocommerce');
                    ?>
</th>
		</tr>
	</thead>
    
	<tfoot>
	
	</tfoot>
	<tbody>
		<?php 
                    if (sizeof($order->get_items()) > 0) {
                        foreach ($order->get_items() as $item) {
                            $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
                            $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
                            ?>
				<tr class="<?php 
                            echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order));
                            ?>
">
					<td  style="text-transform:uppercase;">
						<?php 
                            if ($_product && !$_product->is_visible()) {
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
                            } else {
                                echo apply_filters('woocommerce_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item);
                            }
                            echo apply_filters('woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf('&times; %s', $item['qty']) . '</strong>', $item);
                            $item_meta->display();
                            if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
                                $download_files = $order->get_item_downloads($item);
                                $i = 0;
                                $links = array();
                                foreach ($download_files as $download_id => $file) {
                                    $i++;
                                    $links[] = '<small><a href="' . esc_url($file['download_url']) . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_files) > 1 ? ' ' . $i . ': ' : ': ') . esc_html($file['name']) . '</a></small>';
                                }
                                echo '<br/>' . implode('<br/>', $links);
                            }
                            ?>
					</td>
					<td class="product-total" style="color:#F00">
						<?php 
                            echo $order->get_formatted_line_subtotal($item);
                            ?>
					</td>
				</tr>
				
					<?php 
                        }
                    }
                    ?>
	</tbody>
</table>
<div class="clear"></div>
</td>
<td class="order-actions">
                 
						<?php 
                    $actions = array();
                    if (in_array($order->status, apply_filters('woocommerce_valid_order_statuses_for_payment', array('Incompleta', 'Fallita'), $order))) {
                    }
                    $actions['view'] = array('url' => $order->get_view_order_url(), 'name' => __('Dettagli', 'woocommerce'));
                    $actions = apply_filters('woocommerce_my_account_my_orders_actions', $actions, $order);
                    if ($actions) {
                        foreach ($actions as $key => $action) {
                            echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
                        }
                    }
                    ?>
  				</td>
                    <td class="order-actions">
                    	<?php 
                    $actions = array();
                    $actions['cancel'] = array('url' => $order->get_cancel_order_url(get_permalink(wc_get_page_id('alter-inventory'))), 'name' => __('Cancel', 'woocommerce'));
                    if ($actions) {
                        foreach ($actions as $key => $action) {
                            echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
                        }
                    }
                    ?>
					</td>
				</tr><?php 
                }
                ?>
</tbody>

	</table>
<?php 
            }
            ?>

	
	<?php 
        }
    }
 /**
  * do_payment
  *
  * Process the PayFlow transaction with PayPal.
  *
  * @access public
  * @param mixed $order
  * @param mixed $card_number
  * @param mixed $card_exp
  * @param mixed $card_csc
  * @param string $centinelPAResStatus (default: '')
  * @param string $centinelEnrolled (default: '')
  * @param string $centinelCavv (default: '')
  * @param string $centinelEciFlag (default: '')
  * @param string $centinelXid (default: '')
  * @return void
  */
 function do_payment($order, $card_number, $card_exp, $card_csc, $centinelPAResStatus = '', $centinelEnrolled = '', $centinelCavv = '', $centinelEciFlag = '', $centinelXid = '')
 {
     /*
      * Display message to user if session has expired.
      */
     if (sizeof(WC()->cart->get_cart()) == 0) {
         wc_add_notice(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage &rarr;</a>', 'wc-paypal-express'), home_url()), "error");
     }
     /*
      * Check if the PayPal_PayFlow class has already been established.
      */
     if (!class_exists('PayPal_PayFlow')) {
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php';
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php';
     }
     /**
      * Create PayPal_PayFlow object.
      */
     $PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $this->paypal_user, 'APIPassword' => trim($this->paypal_password), 'APIVendor' => $this->paypal_vendor, 'APIPartner' => $this->paypal_partner);
     $PayPal = new PayPal_PayFlow($PayPalConfig);
     /**
      * Pulled from original Woo extension.
      */
     if (empty($GLOBALS['wp_rewrite'])) {
         $GLOBALS['wp_rewrite'] = new WP_Rewrite();
     }
     $this->add_log($order->get_checkout_order_received_url());
     try {
         /**
          * Parameter set by original Woo.  I can probably ditch this, but leaving it for now.
          */
         $url = $this->testmode == 'yes' ? $this->testurl : $this->liveurl;
         /**
          * PayPal PayFlow Gateway Request Params
          */
         $PayPalRequestData = array('tender' => 'C', 'trxtype' => 'S', 'acct' => $card_number, 'expdate' => $card_exp, 'amt' => $order->get_total(), 'currency' => get_option('woocommerce_currency'), 'dutyamt' => '', 'freightamt' => '', 'taxamt' => '', 'taxexempt' => '', 'comment1' => $order->customer_note ? wptexturize($order->customer_note) : '', 'comment2' => '', 'cvv2' => $card_csc, 'recurring' => '', 'swipe' => '', 'orderid' => preg_replace("/[^0-9,.]/", "", $order->get_order_number()), 'orderdesc' => 'Order ' . $order->get_order_number() . ' on ' . get_bloginfo('name'), 'billtoemail' => $order->billing_email, 'billtophonenum' => '', 'billtofirstname' => $order->billing_first_name, 'billtomiddlename' => '', 'billtolastname' => $order->billing_last_name, 'billtostreet' => $order->billing_address_1 . ' ' . $order->billing_address_2, 'billtocity' => $order->billing_city, 'billtostate' => $order->billing_state, 'billtozip' => $order->billing_postcode, 'billtocountry' => $order->billing_country, 'origid' => '', 'custref' => '', 'custcode' => '', 'custip' => $this->get_user_ip(), 'invnum' => str_replace("#", "", $order->get_order_number()), 'ponum' => '', 'starttime' => '', 'endtime' => '', 'securetoken' => '', 'partialauth' => '', 'authcode' => '');
         /**
          * Shipping info
          */
         if ($order->shipping_address_1) {
             $PayPalRequestData['SHIPTOFIRSTNAME'] = $order->shipping_first_name;
             $PayPalRequestData['SHIPTOLASTNAME'] = $order->shipping_last_name;
             $PayPalRequestData['SHIPTOSTREET'] = $order->shipping_address_1 . ' ' . $order->shipping_address_2;
             $PayPalRequestData['SHIPTOCITY'] = $order->shipping_city;
             $PayPalRequestData['SHIPTOSTATE'] = $order->shipping_state;
             $PayPalRequestData['SHIPTOCOUNTRY'] = $order->shipping_country;
             $PayPalRequestData['SHIPTOZIP'] = $order->shipping_postcode;
         }
         /* Send Item details */
         $item_loop = 0;
         if (sizeof($order->get_items()) > 0) {
             $ITEMAMT = 0;
             foreach ($order->get_items() as $item) {
                 $item['name'] = html_entity_decode($item['name'], ENT_NOQUOTES, 'UTF-8');
                 $_product = $order->get_product_from_item($item);
                 if ($item['qty']) {
                     $sku = $_product->get_sku();
                     if ($_product->product_type == 'variation') {
                         if (empty($sku)) {
                             $sku = $_product->parent->get_sku();
                         }
                         $item_meta = new WC_Order_Item_Meta($item['item_meta']);
                         $meta = $item_meta->display(true, true);
                         if (!empty($meta)) {
                             $item['name'] .= " - " . str_replace(", \n", " - ", $meta);
                         }
                     }
                     if (get_option('woocommerce_prices_include_tax') == 'yes') {
                         $product_price = $order->get_item_subtotal($item, true, false);
                     } else {
                         $product_price = $order->get_item_subtotal($item, false, true);
                     }
                     $PayPalRequestData['L_NUMBER' . $item_loop] = $sku;
                     $PayPalRequestData['L_NAME' . $item_loop] = $item['name'];
                     $PayPalRequestData['L_COST' . $item_loop] = $product_price;
                     $PayPalRequestData['L_QTY' . $item_loop] = $item['qty'];
                     if ($sku) {
                         $PayPalRequestData['L_SKU' . $item_loop] = $sku;
                     }
                     $ITEMAMT += $product_price * $item['qty'];
                     $item_loop++;
                 }
             }
             //Cart Discount
             if ($order->get_cart_discount() > 0) {
                 foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                     $PayPalRequestData['L_NUMBER' . $item_loop] = $code;
                     $PayPalRequestData['L_NAME' . $item_loop] = 'Cart Discount';
                     $PayPalRequestData['L_AMT' . $item_loop] = '-' . WC()->cart->coupon_discount_amounts[$code];
                     $PayPalRequestData['L_QTY' . $item_loop] = 1;
                     $item_loop++;
                 }
                 $ITEMAMT = $ITEMAMT - $order->get_cart_discount();
             }
             //Order Discount
             if ($order->get_order_discount() > 0) {
                 foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                     $PayPalRequestData['L_NUMBER' . $item_loop] = $code;
                     $PayPalRequestData['L_NAME' . $item_loop] = 'Order Discount';
                     $PayPalRequestData['L_AMT' . $item_loop] = '-' . WC()->cart->coupon_discount_amounts[$code];
                     $PayPalRequestData['L_QTY' . $item_loop] = 1;
                     $item_loop++;
                 }
                 $ITEMAMT = $ITEMAMT - $order->get_order_discount();
             }
             if (get_option('woocommerce_prices_include_tax') == 'yes') {
                 $shipping = $order->get_total_shipping() + $order->get_shipping_tax();
                 $tax = 0;
             } else {
                 $shipping = $order->get_total_shipping();
                 $tax = $order->get_total_tax();
             }
             //tax
             if ($tax > 0) {
                 $PayPalRequestData['TAXAMT'] = $tax;
             }
             // Shipping
             if ($shipping > 0) {
                 $PayPalRequestData['FREIGHTAMT'] = $shipping;
             }
             $PayPalRequestData['ITEMAMT'] = number_format($ITEMAMT, 2, '.', '');
         }
         /**
          * Woo's original extension wasn't sending the request with 
          * character count like it's supposed to.  This was added
          * to fix that, but now that we're using my library it's
          * already handled correctly so this won't be necessary.
          */
         /*foreach ($post_data as $key=>$value){
               $send_data[]= $key."[".strlen($value)."]=$value";
           }
           $send_data = implode("&", $send_data);*/
         /**
          * Pass data to to the class and store the $PayPalResult
          */
         $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData);
         /**
          * Log results
          */
         $this->add_log('PayFlow Endpoint: ' . $PayPal->APIEndPoint);
         $this->add_log(print_r($PayPalResult, true));
         /**
          * Error check
          */
         if (empty($PayPalResult['RAWRESPONSE'])) {
             throw new Exception(__('Empty PayPal response.', 'wc_paypal_pro'));
         }
         /** 
          * More logs
          */
         $this->add_log(add_query_arg('key', $order->order_key, add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('thanks')))));
         /**
          * Check for errors or fraud filter warnings and proceed accordingly.
          */
         if (isset($PayPalResult['RESULT']) && ($PayPalResult['RESULT'] == 0 || $PayPalResult['RESULT'] == 126)) {
             // Add order note
             if ($PayPalResult['RESULT'] == 126) {
                 $order->add_order_note($PayPalResult['RESPMSG']);
                 $order->add_order_note($PayPalResult['PREFPSMSG']);
                 $order->add_order_note("The payment was flagged by a fraud filter, please check your PayPal Manager account to review and accept or deny the payment.");
             } else {
                 $order->add_order_note(sprintf(__('PayPal Pro payment completed (PNREF: %s)', 'wc_paypal_pro'), $PayPalResult['PNREF']));
             }
             // Payment complete
             $order->payment_complete();
             // Remove cart
             WC()->cart->empty_cart();
             // Return thank you page redirect
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         } else {
             // Payment failed :(
             $order->update_status('failed', __('PayPal Pro payment failed. Payment was rejected due to an error: ', 'wc_paypal_pro') . '(' . $parsed_response['RESULT'] . ') ' . '"' . $parsed_response['RESPMSG'] . '"');
             wc_add_notice(__('Payment error:', 'wc_paypal_pro') . ' ' . $parsed_response['RESPMSG'], "error");
             return;
         }
     } catch (Exception $e) {
         wc_add_notice(__('Connection error:', 'wc_paypal_pro') . ': "' . $e->getMessage() . '"', "error");
         return;
     }
 }
    /**
     * Output items for display
     */
    function woocommerce_pip_order_items_table($order, $show_price = FALSE)
    {
        $return = '';
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            $sku = $variation = '';
            $sku = $_product->get_sku();
            $item_meta = new WC_Order_Item_Meta($item['item_meta']);
            $variation = '<br/><small>' . $item_meta->display(TRUE, TRUE) . '</small>';
            $return .= '<tr>
			  <td style="text-align:left; padding: 3px;">' . $sku . '</td>
				<td style="text-align:left; padding: 3px;">' . apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $variation . '</td>
				<td style="text-align:left; padding: 3px;">' . $item['qty'] . '</td>';
            if ($show_price) {
                $return .= '<td style="text-align:left; padding: 3px;">';
                if ($order->display_cart_ex_tax || !$order->prices_include_tax) {
                    $ex_tax_label = $order->prices_include_tax ? 1 : 0;
                    $return .= woocommerce_price($order->get_line_subtotal($item), array('ex_tax_label' => $ex_tax_label));
                } else {
                    $return .= woocommerce_price($order->get_line_subtotal($item, TRUE));
                }
                $return .= '
				</td>';
            }
            $return .= '</tr>';
        }
        $return = apply_filters('woocommerce_pip_order_items_table', $return);
        return $return;
    }
}
foreach ($items as $item_id => $item) {
    $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
    // Title
    echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
    // SKU
    if ($show_sku && $_product->get_sku()) {
        echo '<br />(#' . $_product->get_sku() . ')';
    }
    // allow other plugins to add additional product information here
    do_action('woocommerce_order_item_meta_start', $item_id, $item, $order);
    // Variation
    // echo $item_meta->meta ? "\n" . $item_meta->display( true, true ) : '';
    if ($item_meta->meta) {
        $colors = preg_replace("/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\\b/", "", $item_meta->display(true, true));
        $colors = str_replace('color', '', $colors);
        $colors = str_replace(':', '', $colors);
        echo "Color: " . $colors;
    }
    // Quantity
    echo "\n" . sprintf(__('Quantity: %s', 'woocommerce'), $item['qty']);
    // Cost
    echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item));
    // Download URLs
    if ($show_download_links && $_product->exists() && $_product->is_downloadable()) {
        $download_files = $order->get_item_downloads($item);
        $i = 0;
        foreach ($download_files as $download_id => $file) {
            $i++;
            if (count($download_files) > 1) {
Пример #15
0
 /**
  * Get line items to send to paypal
  *
  * @param  WC_Order $order
  * @return array on success, or false when it is not possible to send line items
  */
 private function get_line_items($order)
 {
     // Do not send lines for tax inclusive prices
     if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
         return false;
     }
     // Do not send lines when order discount is present, or too many line items in the order.
     if ($order->get_order_discount() > 0 || sizeof($order->get_items()) + sizeof($order->get_fees()) >= 9) {
         return false;
     }
     $item_loop = 0;
     $args = array();
     $args['tax_cart'] = $order->get_total_tax();
     // Products
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if (!$item['qty']) {
                 continue;
             }
             $item_loop++;
             $product = $order->get_product_from_item($item);
             $item_name = $item['name'];
             $item_meta = new WC_Order_Item_Meta($item['item_meta']);
             if ($meta = $item_meta->display(true, true)) {
                 $item_name .= ' ( ' . $meta . ' )';
             }
             $args['item_name_' . $item_loop] = $this->paypal_item_name($item_name);
             $args['quantity_' . $item_loop] = $item['qty'];
             $args['amount_' . $item_loop] = $order->get_item_subtotal($item, false);
             if ($args['amount_' . $item_loop] < 0) {
                 return false;
                 // Abort - negative line
             }
             if ($product->get_sku()) {
                 $args['item_number_' . $item_loop] = $product->get_sku();
             }
         }
     }
     // Discount
     if ($order->get_cart_discount() > 0) {
         $args['discount_amount_cart'] = round($order->get_cart_discount(), 2);
     }
     // Fees
     if (sizeof($order->get_fees()) > 0) {
         foreach ($order->get_fees() as $item) {
             $item_loop++;
             $args['item_name_' . $item_loop] = $this->paypal_item_name($item['name']);
             $args['quantity_' . $item_loop] = 1;
             $args['amount_' . $item_loop] = $item['line_total'];
             if ($args['amount_' . $item_loop] < 0) {
                 return false;
                 // Abort - negative line
             }
         }
     }
     // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
     if ($order->get_total_shipping() > 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = $this->paypal_item_name(sprintf(__('Shipping via %s', 'woocommerce'), $order->get_shipping_method()));
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = number_format($order->get_total_shipping(), 2, '.', '');
     }
     return $args;
 }
Пример #16
0
        /**
         * Output custom columns for coupons
         * @param  string $column
         */
        public function render_shop_order_columns($column)
        {
            global $post, $woocommerce, $the_order;
            if (empty($the_order) || $the_order->id != $post->ID) {
                $the_order = wc_get_order($post->ID);
            }
            switch ($column) {
                case 'order_status':
                    printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->get_status()), wc_get_order_status_name($the_order->get_status()), wc_get_order_status_name($the_order->get_status()));
                    break;
                case 'order_date':
                    if ('0000-00-00 00:00:00' == $post->post_date) {
                        $t_time = $h_time = __('Unpublished', 'woocommerce');
                    } else {
                        $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
                        $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post);
                    }
                    echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>';
                    break;
                case 'customer_message':
                    if ($the_order->customer_message) {
                        echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>';
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'order_items':
                    echo '<a href="#" class="show_order_items">' . apply_filters('woocommerce_admin_order_item_count', sprintf(_n('%d item', '%d items', $the_order->get_item_count(), 'woocommerce'), $the_order->get_item_count()), $the_order) . '</a>';
                    if (sizeof($the_order->get_items()) > 0) {
                        echo '<table class="order_items" cellspacing="0">';
                        foreach ($the_order->get_items() as $item) {
                            $product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item);
                            $item_meta = new WC_Order_Item_Meta($item, $product);
                            $item_meta_html = $item_meta->display(true, true);
                            ?>
						<tr class="<?php 
                            echo apply_filters('woocommerce_admin_order_item_class', '', $item);
                            ?>
">
							<td class="qty"><?php 
                            echo absint($item['qty']);
                            ?>
</td>
							<td class="name">
								<?php 
                            if ($product) {
                                ?>
									<?php 
                                echo wc_product_sku_enabled() && $product->get_sku() ? $product->get_sku() . ' - ' : '';
                                ?>
<a href="<?php 
                                echo get_edit_post_link($product->id);
                                ?>
" title="<?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
"><?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
</a>
								<?php 
                            } else {
                                ?>
									<?php 
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item, false);
                                ?>
								<?php 
                            }
                            ?>
								<?php 
                            if (!empty($item_meta_html)) {
                                ?>
									<a class="tips" href="#" data-tip="<?php 
                                echo esc_attr($item_meta_html);
                                ?>
">[?]</a>
								<?php 
                            }
                            ?>
							</td>
						</tr>
						<?php 
                        }
                        echo '</table>';
                    } else {
                        echo '&ndash;';
                    }
                    break;
                case 'shipping_address':
                    if ($address = $the_order->get_formatted_shipping_address()) {
                        echo '<a target="_blank" href="' . esc_url($the_order->get_shipping_address_map_url()) . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $address)) . '</a>';
                    } else {
                        echo '&ndash;';
                    }
                    if ($the_order->get_shipping_method()) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>';
                    }
                    break;
                case 'order_notes':
                    if ($post->comment_count) {
                        // check the status of the post
                        $status = 'trash' !== $post->post_status ? '' : 'post-trashed';
                        $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status));
                        $latest_note = current($latest_notes);
                        if ($post->comment_count == 1) {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>';
                        } elseif (isset($latest_note->comment_content)) {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip($latest_note->comment_content . '<br/><small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') . '">' . __('Yes', 'woocommerce') . '</span>';
                        } else {
                            echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip(sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count)) . '">' . __('Yes', 'woocommerce') . '</span>';
                        }
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'order_total':
                    echo $the_order->get_formatted_order_total();
                    if ($the_order->payment_method_title) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>';
                    }
                    break;
                case 'order_title':
                    $customer_tip = array();
                    if ($address = $the_order->get_formatted_billing_address()) {
                        $customer_tip[] = __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>';
                    }
                    if ($the_order->billing_phone) {
                        $customer_tip[] = __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone;
                    }
                    if ($the_order->user_id) {
                        $user_info = get_userdata($the_order->user_id);
                    }
                    if (!empty($user_info)) {
                        $username = '******' . absint($user_info->ID) . '">';
                        if ($user_info->first_name || $user_info->last_name) {
                            $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name));
                        } else {
                            $username .= esc_html(ucfirst($user_info->display_name));
                        }
                        $username .= '</a>';
                    } else {
                        if ($the_order->billing_first_name || $the_order->billing_last_name) {
                            $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name);
                        } else {
                            $username = __('Guest', 'woocommerce');
                        }
                    }
                    printf(_x('%s by %s', 'Order number by X', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '" class="row-title"><strong>#' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username);
                    if ($the_order->billing_email) {
                        echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>';
                    }
                    echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'woocommerce') . '</span></button>';
                    break;
                case 'order_actions':
                    ?>
<p>
					<?php 
                    do_action('woocommerce_admin_order_actions_start', $the_order);
                    $actions = array();
                    if ($the_order->has_status(array('pending', 'on-hold'))) {
                        $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing");
                    }
                    if ($the_order->has_status(array('pending', 'on-hold', 'processing'))) {
                        $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $post->ID), 'woocommerce-mark-order-status'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete");
                    }
                    $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view");
                    $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order);
                    foreach ($actions as $action) {
                        printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                    }
                    do_action('woocommerce_admin_order_actions_end', $the_order);
                    ?>
				</p><?php 
                    break;
            }
        }
Пример #17
0
	if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {

		// Title
		echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );

		// SKU
		if ( $show_sku && $_product->get_sku() ) {
			echo ' (#' . $_product->get_sku() . ')';
		}

		// allow other plugins to add additional product information here
		do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );

		// Variation
		echo ( $item_meta_content = $item_meta->display( true, true ) ) ? "\n" . $item_meta_content : '';

		// Quantity
		echo "\n" . sprintf( __( 'Anzahl: %s', 'woocommerce' ), apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) );

		// Cost
		echo "\n" . sprintf( __( 'Preis: %s', 'woocommerce' ), $order->get_formatted_line_subtotal( $item ) );

		// Download URLs
		if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
			$download_files = $order->get_item_downloads( $item );
			$i              = 0;

			foreach ( $download_files as $download_id => $file ) {
				$i++;
 public static function calculate($order, $send_items = false)
 {
     $PaymentOrderItems = array();
     $ctr = $giftwrapamount = $total_items = $total_discount = $total_tax = $shipping = 0;
     $ITEMAMT = 0;
     if ($order) {
         $order_total = $order->get_total();
         $items = $order->get_items();
         /*
          * Set shipping and tax values.
          */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = $order->get_total_shipping() + $order->get_shipping_tax();
             $tax = 0;
         } else {
             $shipping = $order->get_total_shipping();
             $tax = $order->get_total_tax();
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             $tax = $order->get_total_tax();
         }
     } else {
         //if empty order we get data from cart
         $order_total = WC()->cart->total;
         $items = WC()->cart->get_cart();
         /**
          * Get shipping and tax.
          */
         if (get_option('woocommerce_prices_include_tax') == 'yes') {
             $shipping = WC()->cart->shipping_total + WC()->cart->shipping_tax_total;
             $tax = 0;
         } else {
             $shipping = WC()->cart->shipping_total;
             $tax = WC()->cart->get_taxes_total();
         }
         if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
             $tax = WC()->cart->get_taxes_total();
         }
     }
     if ($send_items) {
         foreach ($items as $item) {
             /*
              * Get product data from WooCommerce
              */
             if ($order) {
                 $_product = $order->get_product_from_item($item);
                 $qty = absint($item['qty']);
                 $item_meta = new WC_Order_Item_Meta($item, $_product);
                 $meta = $item_meta->display(true, true);
             } else {
                 $_product = $item['data'];
                 $qty = absint($item['quantity']);
                 $meta = WC()->cart->get_item_data($item, true);
             }
             $sku = $_product->get_sku();
             $item['name'] = html_entity_decode($_product->get_title(), ENT_NOQUOTES, 'UTF-8');
             if ($_product->product_type == 'variation') {
                 if (empty($sku)) {
                     $sku = $_product->parent->get_sku();
                 }
                 if (!empty($meta)) {
                     $item['name'] .= " - " . str_replace(", \n", " - ", $meta);
                 }
             }
             $Item = array('name' => $item['name'], 'desc' => '', 'amt' => self::round($item['line_subtotal'] / $qty), 'number' => $sku, 'qty' => $qty);
             array_push($PaymentOrderItems, $Item);
             $ITEMAMT += self::round($item['line_subtotal'] / $qty) * $qty;
         }
         /**
          * Add custom Woo cart fees as line items
          */
         foreach (WC()->cart->get_fees() as $fee) {
             $Item = array('name' => $fee->name, 'desc' => '', 'amt' => self::number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1);
             /**
              * The gift wrap amount actually has its own parameter in
              * DECP, so we don't want to include it as one of the line
              * items.
              */
             if ($Item['number'] != 'gift-wrap') {
                 array_push($PaymentOrderItems, $Item);
                 $ITEMAMT += self::round($fee->amount);
             } else {
                 $giftwrapamount = self::round($fee->amount);
             }
             $ctr++;
         }
         //caculate discount
         if ($order) {
             if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) {
                 if ($order->get_cart_discount() > 0) {
                     foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                         $Item = array('name' => 'Cart Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                     }
                     $total_discount -= $order->get_cart_discount();
                 }
                 if ($order->get_order_discount() > 0) {
                     foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                         $Item = array('name' => 'Order Discount', 'number' => $code, 'qty' => '1', 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                     }
                     $total_discount -= $order->get_order_discount();
                 }
             } else {
                 if ($order->get_total_discount() > 0) {
                     $Item = array('name' => 'Total Discount', 'qty' => 1, 'amt' => -self::number_format($order->get_total_discount()), 'number' => implode(", ", $order->get_used_coupons()));
                     array_push($PaymentOrderItems, $Item);
                     $total_discount -= $order->get_total_discount();
                 }
             }
         } else {
             if (WC()->cart->get_cart_discount_total() > 0) {
                 foreach (WC()->cart->get_coupons('cart') as $code => $coupon) {
                     $Item = array('name' => 'Cart Discount', 'qty' => '1', 'number' => $code, 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                     array_push($PaymentOrderItems, $Item);
                     $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]);
                 }
             }
             if (!AngellEYE_Gateway_Paypal::is_wc_version_greater_2_3()) {
                 if (WC()->cart->get_order_discount_total() > 0) {
                     foreach (WC()->cart->get_coupons('order') as $code => $coupon) {
                         $Item = array('name' => 'Order Discount', 'qty' => '1', 'number' => $code, 'amt' => '-' . self::number_format(WC()->cart->coupon_discount_amounts[$code]));
                         array_push($PaymentOrderItems, $Item);
                         $total_discount -= self::number_format(WC()->cart->coupon_discount_amounts[$code]);
                     }
                 }
             }
         }
     }
     if ($tax > 0) {
         $tax = self::number_format($tax);
     }
     if ($shipping > 0) {
         $shipping = self::number_format($shipping);
     }
     if ($total_discount) {
         $total_discount = self::round($total_discount);
     }
     if (empty($ITEMAMT)) {
         $cart_fees = WC()->cart->get_fees();
         if (isset($cart_fees[0]->id) && $cart_fees[0]->id == 'gift-wrap') {
             $giftwrapamount = isset($cart_fees[0]->amount) ? $cart_fees[0]->amount : 0;
         } else {
             $giftwrapamount = 0;
         }
         $Payment['itemamt'] = $order_total - $tax - $shipping - $giftwrapamount;
     } else {
         $Payment['itemamt'] = self::number_format($ITEMAMT + $total_discount);
     }
     /*
      * Set tax
      */
     if ($tax > 0) {
         $Payment['taxamt'] = self::number_format($tax);
         // Required if you specify itemized L_TAXAMT fields.  Sum of all tax items in this order.
     } else {
         $Payment['taxamt'] = 0;
     }
     /*
      * Set shipping
      */
     if ($shipping > 0) {
         $Payment['shippingamt'] = self::number_format($shipping);
         // Total shipping costs for this order.  If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT.
     } else {
         $Payment['shippingamt'] = 0;
     }
     $Payment['order_items'] = $PaymentOrderItems;
     // Rounding amendment
     if (trim(self::number_format($order_total)) !== trim(self::number_format($Payment['itemamt'] + $giftwrapamount + $tax + $shipping))) {
         $diffrence_amount = AngellEYE_Gateway_Paypal::get_diffrent($order_total, $Payment['itemamt'] + $tax + $shipping);
         if ($shipping > 0) {
             $Payment['shippingamt'] = self::number_format($shipping + $diffrence_amount);
         } elseif ($tax > 0) {
             $Payment['taxamt'] = self::number_format($tax + $diffrence_amount);
         } else {
             //make change to itemamt
             $Payment['itemamt'] = self::number_format($Payment['itemamt'] + $diffrence_amount);
             //also make change to the first item
             if ($send_items) {
                 $Payment['order_items'][0]['amt'] = self::number_format($Payment['order_items'][0]['amt'] + $diffrence_amount / $Payment['order_items'][0]['qty']);
             }
         }
     }
     return $Payment;
 }
 $order->set_total(WC()->cart->total);
 // Cart Contents
 if (sizeof($order->get_items()) > 0) {
     foreach ($order->get_items() as $item) {
         if ($item['qty']) {
             $_product = $order->get_product_from_item($item);
             // We manually calculate the tax percentage here
             if ($_product->is_taxable() && $order->get_line_tax($item) > 0) {
                 // Calculate tax percentage
                 $item_tax_percentage = round($order->get_item_tax($item, false) / $order->get_item_total($item, false, false), 2) * 100;
             } else {
                 $item_tax_percentage = 00;
             }
             $item_name = $item['name'];
             $item_meta = new WC_Order_Item_Meta($item);
             if ($meta = $item_meta->display(true, true)) {
                 $item_name .= ' ( ' . $meta . ' )';
             }
             // apply_filters to item price so we can filter this if needed
             $hygglig_item_price_including_tax = $order->get_item_total($item, true);
             $item_price = apply_filters('hygglig_item_price_including_tax', $hygglig_item_price_including_tax);
             // Get SKU or product id [TEMP ONLY USE ID]
             $reference = $_product->id;
             //If variation of product - add ID
             if ($item['variation_id']) {
                 $reference .= $item['variation_id'];
             }
             //Get product description
             $product_description = trim(get_post($item['product_id'])->post_content);
             //Fix desc
             if (strlen($product_description) == 0) {
 /**
  * Get the order data format for a single column for all line items, compatible with the legacy (pre 3.0) CSV Export format
  *
  * Note this code was adapted from the old code to maintain compatibility as close as possible, so it should
  * not be modified unless absolutely necessary
  *
  * @since 3.0
  * @param array $order_data an array of order data for the given order
  * @param WC_Order $order the WC_Order object
  * @return array modified order data
  */
 private function get_legacy_single_column_line_item($order_data, WC_Order $order)
 {
     $line_items = array();
     foreach ($order->get_items() as $_ => $item) {
         $product = $order->get_product_from_item($item);
         if (!is_object($product)) {
             $product = new WC_Product(0);
         }
         $line_item = $item['name'];
         if ($product->get_sku()) {
             $line_item .= ' (' . $product->get_sku() . ')';
         }
         $line_item .= ' x' . $item['qty'];
         $item_meta = new WC_Order_Item_Meta($item);
         $variation = $item_meta->display(true, true);
         if ($variation) {
             $line_item .= ' - ' . str_replace(array("\r", "\r\n", "\n"), '', $variation);
         }
         $line_items[] = str_replace(array('&#8220;', '&#8221;'), '', $line_item);
     }
     $order_data['order_items'] = implode('; ', $line_items);
     // convert country codes to full name
     if (isset(WC()->countries->countries[$order->billing_country])) {
         $order_data['billing_country'] = WC()->countries->countries[$order->billing_country];
     }
     if (isset(WC()->countries->countries[$order->shipping_country])) {
         $order_data['shipping_country'] = WC()->countries->countries[$order->shipping_country];
     }
     // set order ID to order number
     $order_data['order_id'] = ltrim($order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-customer-order-csv-export'));
     return $order_data;
 }
Пример #21
0
_e('Price', 'woocommerce-germanized-pro');
?>
</th>
		</tr>
	</thead>
	<tbody>
		<?php 
if ($invoice->items) {
    ?>
			<?php 
    foreach ($invoice->items as $item) {
        $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
        $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
        $item_meta_print = '';
        if ($item_meta->meta) {
            $item_meta_print = $item_meta->display(true, true, '_', ", ");
        }
        ?>
				<tr class="data" nobr="true">
					<td class="first" width="<?php 
        echo $first_width;
        ?>
">
						<?php 
        echo $item['name'];
        ?>
 
						<?php 
        if ($invoice->get_option('show_sku') && is_object($_product) && $_product->get_sku()) {
            ?>
							<small>[<?php 
    ?>
</th>
            </tr>
            </thead>
            <tbody>
            <?php 
    foreach ($shipment->get_items() as $item) {
        // get the product; if this variation or product has been deleted, this will return null...
        $_product = $shipment->get_product_from_item($item);
        $sku = $variation = '';
        if ($_product) {
            $sku = $_product->get_sku();
        }
        $item_meta = new WC_Order_Item_Meta($item['item_meta']);
        // first, is there order item meta avaialble to display?
        $variation = $item_meta->display(true, true);
        if (!$variation && $_product && isset($_product->variation_data)) {
            // otherwise (for an order added through the admin) lets display the formatted variation data so we have something to fall back to
            $variation = wc_get_formatted_variation($_product->variation_data, true);
        }
        if ($variation) {
            $variation = '<br/><small>' . $variation . '</small>';
        }
        ?>
                <tr>
                    <td><?php 
        echo apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $variation;
        ?>
</td>
                    <td align="center"><?php 
        echo $item['qty'];
Пример #23
0
_e('Total', 'woocommerce');
?>
</th>
            </tr>
        </thead>
       
        <tbody>
            <?php 
if (sizeof($order->get_items()) > 0) {
    foreach ($order->get_items() as $item) {
        $_product = get_product($item['variation_id'] ? $item['variation_id'] : $item['product_id']);
        echo '
					<tr class = "' . esc_attr(apply_filters('woocommerce_order_table_item_class', 'order_table_item', $item, $order)) . '">
						<td class="product-name">' . apply_filters('woocommerce_order_table_product_title', '<a href="' . get_permalink($item['product_id']) . '">' . $item['name'] . '</a>', $item) . ' ' . apply_filters('woocommerce_order_table_item_quantity', '<strong class="product-quantity">&times; ' . $item['qty'] . '</strong>', $item);
        $item_meta = new WC_Order_Item_Meta($item['item_meta']);
        $item_meta->display();
        if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
            $download_file_urls = $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item);
            $i = 0;
            $links = array();
            foreach ($download_file_urls as $file_url => $download_file_url) {
                $filename = woocommerce_get_filename_from_url($file_url);
                $links[] = '<small><a href="' . $download_file_url . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_file_urls) > 1 ? ' ' . ($i + 1) . ': ' : ': ') . $filename . '</a></small>';
                $i++;
            }
            echo implode('<br/>', $links);
        }
        echo '</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)) {
 /**
  * Get the current order items
  */
 public function get_order_items()
 {
     global $woocommerce;
     global $_product;
     $items = $this->order->get_items();
     $data_list = array();
     if (sizeof($items) > 0) {
         foreach ($items as $item_id => $item) {
             // Array with data for the pdf template
             $data = array();
             // Set the item_id
             $data['item_id'] = $item_id;
             // Set the id
             $data['product_id'] = $item['product_id'];
             $data['variation_id'] = $item['variation_id'];
             // Set item name
             $data['name'] = $item['name'];
             // Set item quantity
             $data['quantity'] = $item['qty'];
             // Set the line total (=after discount)
             $data['line_total'] = $this->wc_price($item['line_total']);
             $data['single_line_total'] = $this->wc_price($item['line_total'] / max(1, $item['qty']));
             $data['line_tax'] = $this->wc_price($item['line_tax']);
             $data['single_line_tax'] = $this->wc_price($item['line_tax'] / max(1, $item['qty']));
             $line_tax_data = maybe_unserialize(isset($item['line_tax_data']) ? $item['line_tax_data'] : '');
             $data['tax_rates'] = $this->get_tax_rate($item['tax_class'], $item['line_total'], $item['line_tax'], $line_tax_data);
             // Set the line subtotal (=before discount)
             $data['line_subtotal'] = $this->wc_price($item['line_subtotal']);
             $data['line_subtotal_tax'] = $this->wc_price($item['line_subtotal_tax']);
             $data['ex_price'] = $this->get_formatted_item_price($item, 'total', 'excl');
             $data['price'] = $this->get_formatted_item_price($item, 'total');
             $data['order_price'] = $this->order->get_formatted_line_subtotal($item);
             // formatted according to WC settings
             // Calculate the single price with the same rules as the formatted line subtotal (!)
             // = before discount
             $data['ex_single_price'] = $this->get_formatted_item_price($item, 'single', 'excl');
             $data['single_price'] = $this->get_formatted_item_price($item, 'single');
             // Pass complete item array
             $data['item'] = $item;
             // Create the product to display more info
             $data['product'] = null;
             $product = $this->order->get_product_from_item($item);
             // Checking fo existance, thanks to MDesigner0
             if (!empty($product)) {
                 // Set the thumbnail id DEPRICATED (does not support thumbnail sizes), use thumbnail_path or thumbnail instead
                 $data['thumbnail_id'] = $this->get_thumbnail_id($product);
                 // Thumbnail (full img tag)
                 $data['thumbnail'] = $this->get_thumbnail($product);
                 // Set the single price (turned off to use more consistent calculated price)
                 // $data['single_price'] = woocommerce_price ( $product->get_price() );
                 // Set item SKU
                 $data['sku'] = $product->get_sku();
                 // Set item weight
                 $data['weight'] = $product->get_weight();
                 // Set item dimensions
                 $data['dimensions'] = $product->get_dimensions();
                 // Pass complete product object
                 $data['product'] = $product;
             }
             // Set item meta
             if (version_compare(WOOCOMMERCE_VERSION, '2.4', '<')) {
                 $meta = new WC_Order_Item_Meta($item['item_meta'], $product);
             } else {
                 // pass complete item for WC2.4+
                 $meta = new WC_Order_Item_Meta($item, $product);
             }
             $data['meta'] = $meta->display(false, true);
             $data_list[$item_id] = apply_filters('wpo_wcpdf_order_item_data', $data, $this->order);
         }
     }
     return apply_filters('wpo_wcpdf_order_items_data', $data_list, $this->order);
 }
Пример #25
0
        $download_file_urls = $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item);
        $i = 0;
        foreach ($download_file_urls as $file_url => $download_file_url) {
            echo '<br/><small>';
            $filename = woocommerce_get_filename_from_url($file_url);
            if (count($download_file_urls) > 1) {
                echo sprintf(__('Download %d:', 'woocommerce'), $i + 1);
            } elseif ($i == 0) {
                echo __('Download:', 'woocommerce');
            }
            echo ' <a href="' . $download_file_url . '" target="_blank">' . $filename . '</a></small>';
            $i++;
        }
    }
    // Variation
    echo $item_meta->meta ? '<br/><small>' . nl2br($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))) {
        ?>
Пример #26
0
function access_woocommerce_view_order($order_id)
{
    global $woocommerce;
    $order = new WC_Order($order_id);
    ?>
    <div class="avada-order-details woocommerce-content-box full-width">
        <h2><?php 
    _e('Order Details', 'woocommerce');
    ?>
</h2>
        <table class="shop_table order_details">
            <thead>
            <tr>
                <th class="product-name"><?php 
    _e('Product', 'woocommerce');
    ?>
</th>
                <th class="product-quantity"><?php 
    _e('Quantity', 'woocommerce');
    ?>
</th>
                <th class="product-total"><?php 
    _e('Total', 'woocommerce');
    ?>
</th>
            </tr>
            </thead>
            <tfoot>
            <?php 
    if ($totals = $order->get_order_item_totals()) {
        foreach ($totals as $total) {
            ?>
                        <tr>
                            <td class="filler-td">&nbsp;</td>
                            <th scope="row"><?php 
            echo $total['label'];
            ?>
</th>
                            <td class="product-total"><?php 
            echo $total['value'];
            ?>
</td>
                        </tr>
                    <?php 
        }
    }
    ?>
            </tfoot>
            <tbody>
            <?php 
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
            $item_meta = new WC_Order_Item_Meta($item['item_meta']);
            ?>
                        <tr class="<?php 
            echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order));
            ?>
">
                            <td class="product-name">
                        <span class="product-thumbnail">
                            <?php 
            $thumbnail = apply_filters('woocommerce_cart_item_thumbnail', $_product->get_image());
            if (!$_product->is_visible()) {
                echo $thumbnail;
            } else {
                printf('<a href="%s">%s</a>', $_product->get_permalink(), $thumbnail);
            }
            ?>
                        </span>

                                <div class="product-info">
                                    <?php 
            if ($_product && !$_product->is_visible()) {
                echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
            } else {
                echo apply_filters('woocommerce_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item);
            }
            $item_meta->display();
            if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
                $download_files = $order->get_item_downloads($item);
                $i = 0;
                $links = array();
                foreach ($download_files as $download_id => $file) {
                    $i++;
                    $links[] = '<small><a href="' . esc_url($file['download_url']) . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_files) > 1 ? ' ' . $i . ': ' : ': ') . esc_html($file['name']) . '</a></small>';
                }
                echo '<br/>' . implode('<br/>', $links);
            }
            ?>
                                </div>
                            </td>
                            <td class="product-quantity">
                                <?php 
            echo apply_filters('woocommerce_order_item_quantity_html', $item['qty'], $item);
            ?>
                            </td>
                            <td class="product-total">
                                <?php 
            echo $order->get_formatted_line_subtotal($item);
            ?>
                            </td>
                        </tr>
                        <?php 
            if (in_array($order->status, array('processing', 'completed')) && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
                ?>
                            <tr class="product-purchase-note">
                                <td colspan="3"><?php 
                echo apply_filters('the_content', $purchase_note);
                ?>
</td>
                            </tr>
                        <?php 
            }
        }
    }
    do_action('woocommerce_order_items_table', $order);
    ?>
            </tbody>
        </table>
        <?php 
    do_action('woocommerce_order_details_after_order_table', $order);
    ?>
    </div>

    <div class="avada-customer-details woocommerce-content-box full-width">
        <header>
            <h2><?php 
    _e('Customer details', 'woocommerce');
    ?>
</h2>
        </header>
        <dl class="customer_details">
            <?php 
    if ($order->billing_email) {
        echo '<dt>' . __('Email:', 'woocommerce') . '</dt> <dd>' . $order->billing_email . '</dd><br />';
    }
    if ($order->billing_phone) {
        echo '<dt>' . __('Telephone:', 'woocommerce') . '</dt> <dd>' . $order->billing_phone . '</dd>';
    }
    // Additional customer details hook
    do_action('woocommerce_order_details_after_customer_details', $order);
    ?>
        </dl>

        <?php 
    if (get_option('woocommerce_ship_to_billing_address_only') === 'no' && get_option('woocommerce_calc_shipping') !== 'no') {
        ?>

        <div class="col2-set addresses">

            <div class="col-1">

                <?php 
    }
    ?>

                <header class="title">
                    <h3><?php 
    _e('Billing Address', 'woocommerce');
    ?>
</h3>
                </header>
                <address><p>
                        <?php 
    if (!$order->get_formatted_billing_address()) {
        _e('N/A', 'woocommerce');
    } else {
        echo $order->get_formatted_billing_address();
    }
    ?>
                    </p></address>

                <?php 
    if (get_option('woocommerce_ship_to_billing_address_only') === 'no' && get_option('woocommerce_calc_shipping') !== 'no') {
        ?>

            </div>
            <!-- /.col-1 -->

            <div class="col-2">

                <header class="title">
                    <h3><?php 
        _e('Shipping Address', 'woocommerce');
        ?>
</h3>
                </header>
                <address><p>
                        <?php 
        if (!$order->get_formatted_shipping_address()) {
            _e('N/A', 'woocommerce');
        } else {
            echo $order->get_formatted_shipping_address();
        }
        ?>
                    </p></address>

            </div>
            <!-- /.col-2 -->

        </div>
        <!-- /.col2-set -->

    <?php 
    }
    ?>

        <div class="clear"></div>

    </div>

<?php 
}
 /**
  * Get PayPal Args for passing to PP
  *
  * @access public
  * @param mixed $order
  * @return array
  */
 function get_paypal_args($order)
 {
     global $woocommerce;
     $order_id = $order->id;
     if ('yes' == $this->debug) {
         $this->log->add('paypal', 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url);
     }
     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_woocommerce_currency(), 'charset' => 'UTF-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => add_query_arg('utm_nooverride', '1', $this->get_return_url($order)), 'cancel_return' => $order->get_cancel_order_url(), 'page_style' => $this->page_style, 'BUTTONSOURCE' => 'WooThemes_Cart', 'invoice' => $this->invoice_prefix . ltrim($order->get_order_number(), '#'), 'custom' => serialize(array($order_id, $order->order_key)), 'notify_url' => $this->notify_url, '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), $phone_args);
     // Shipping
     if ($this->send_shipping == 'yes') {
         $paypal_args['address_override'] = $this->address_override == 'yes' ? 1 : 0;
         $paypal_args['no_shipping'] = 0;
         // 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 as a single item
     if (get_option('woocommerce_prices_include_tax') == 'yes' || $order->get_order_discount() > 0 || sizeof($order->get_items()) + sizeof($order->get_fees()) >= 9) {
         // 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->get_order_number()) . " - " . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->get_total() - $order->get_shipping() - $order->get_shipping_tax() + $order->get_order_discount(), 2, '.', '');
         // Shipping Cost
         // No longer using shipping_1 because
         //		a) paypal ignore it if *any* shipping rules are within paypal
         //		b) paypal ignore anything over 5 digits, so 999.99 is the max
         // $paypal_args['shipping_1']		= number_format( $order->get_shipping() + $order->get_shipping_tax() , 2, '.', '' );
         if ($order->get_shipping() + $order->get_shipping_tax() > 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() + $order->get_shipping_tax(), 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 WC_Order_Item_Meta($item['item_meta']);
                     if ($meta = $item_meta->display(true, true)) {
                         $item_name .= ' ( ' . $meta . ' )';
                     }
                     $paypal_args['item_name_' . $item_loop] = html_entity_decode($item_name, ENT_NOQUOTES, 'UTF-8');
                     $paypal_args['quantity_' . $item_loop] = $item['qty'];
                     $paypal_args['amount_' . $item_loop] = $order->get_item_subtotal($item, false);
                     if ($product->get_sku()) {
                         $paypal_args['item_number_' . $item_loop] = $product->get_sku();
                     }
                 }
             }
         }
         // Discount
         if ($order->get_cart_discount() > 0) {
             $paypal_args['discount_amount_cart'] = round($order->get_cart_discount(), 2);
         }
         // Fees
         if (sizeof($order->get_fees()) > 0) {
             foreach ($order->get_fees() as $item) {
                 $item_loop++;
                 $paypal_args['item_name_' . $item_loop] = $item['name'];
                 $paypal_args['quantity_' . $item_loop] = 1;
                 $paypal_args['amount_' . $item_loop] = $item['line_total'];
             }
         }
         // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
         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;
 }
Пример #28
0
 * @package 	WooCommerce/Templates/Emails/Plain
 * @version     2.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce;
foreach ($items as $item) {
    // Get/prep product data
    $_product = $order->get_product_from_item($item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta']);
    // Title, sku, qty, price
    echo apply_filters('woocommerce_order_product_title', $item['name'], $_product);
    echo $show_sku && $_product->get_sku() ? ' (#' . $_product->get_sku() . ')' : '';
    // Variation
    echo $item_meta->meta ? "\n" . nl2br($item_meta->display(true, true)) : '';
    // Quantity
    echo "\n" . sprintf(__('Quantity: %s', 'woocommerce'), $item['qty']);
    // Cost
    echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item));
    // Download URLs
    if ($show_download_links && $_product->exists() && $_product->is_downloadable()) {
        echo "\n" . implode("\n", $order->get_downloadable_file_urls($item['product_id'], $item['variation_id'], $item));
    }
    // Note
    if ($show_purchase_note && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
        echo "\n" . nl2br($purchase_note);
    }
    echo "\n\n";
}
Пример #29
0
    exit;
    // Exit if accessed directly
}
foreach ($items as $item_id => $item) {
    $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
    $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
    // Title
    echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
    // SKU
    if ($show_sku && $_product->get_sku()) {
        echo ' (#' . $_product->get_sku() . ')';
    }
    // allow other plugins to add additional product information here
    do_action('woocommerce_order_item_meta_start', $item_id, $item, $order);
    // Variation
    echo $item_meta->meta ? "\n" . $item_meta->display(true, true) : '';
    // Quantity
    echo "\n" . sprintf(__('Quantity: %s', 'woocommerce'), $item['qty']);
    // Cost
    echo "\n" . sprintf(__('Cost: %s', 'woocommerce'), $order->get_formatted_line_subtotal($item));
    // Download URLs
    if ($show_download_links && $_product->exists() && $_product->is_downloadable()) {
        $download_files = $order->get_item_downloads($item);
        $i = 0;
        foreach ($download_files as $download_id => $file) {
            $i++;
            if (count($download_files) > 1) {
                $prefix = sprintf(__('Download %d', 'woocommerce'), $i);
            } elseif ($i == 1) {
                $prefix = __('Download', 'woocommerce');
            }
Пример #30
0
 /**
  * Get the current order items
  */
 public function get_order_items()
 {
     global $woocommerce;
     global $_product;
     $items = $this->order->get_items();
     $data_list = array();
     if (sizeof($items) > 0) {
         foreach ($items as $item) {
             // Array with data for the pdf template
             $data = array();
             // Set the id
             $data['product_id'] = $item['product_id'];
             $data['variation_id'] = $item['variation_id'];
             // Set item name
             $data['name'] = $item['name'];
             // Set item quantity
             $data['quantity'] = $item['qty'];
             // Set the line total (=after discount)
             $quantity_divider = $item['qty'] == 0 ? 1 : $item['qty'];
             // prevent division by zero
             $data['line_total'] = $this->wc_price($item['line_total']);
             $data['single_line_total'] = $this->wc_price($item['line_total'] / $quantity_divider);
             $data['line_tax'] = $this->wc_price($item['line_tax']);
             $data['single_line_tax'] = $this->wc_price($item['line_tax'] / $quantity_divider);
             $data['tax_rates'] = $this->get_tax_rate($item['tax_class'], $item['line_total'], $item['line_tax']);
             // Set the line subtotal (=before discount)
             $data['line_subtotal'] = $this->wc_price($item['line_subtotal']);
             $data['line_subtotal_tax'] = $this->wc_price($item['line_subtotal_tax']);
             $data['ex_price'] = $this->get_formatted_item_price($item, 'total', 'excl');
             $data['price'] = $this->get_formatted_item_price($item, 'total');
             $data['order_price'] = $this->order->get_formatted_line_subtotal($item);
             // formatted according to WC settings
             // Calculate the single price with the same rules as the formatted line subtotal (!)
             // = before discount
             $data['ex_single_price'] = $this->get_formatted_item_price($item, 'single', 'excl');
             $data['single_price'] = $this->get_formatted_item_price($item, 'single');
             // Set item meta and replace it when it is empty
             $meta = new WC_Order_Item_Meta($item['item_meta']);
             $data['meta'] = $meta->display(false, true);
             // Pass complete item array
             $data['item'] = $item;
             // Create the product to display more info
             $data['product'] = null;
             $product = $this->order->get_product_from_item($item);
             // Checking fo existance, thanks to MDesigner0
             if (!empty($product)) {
                 // Set the thumbnail id
                 $data['thumbnail_id'] = $this->get_thumbnail_id($product->id);
                 // Set the thumbnail server path
                 $data['thumbnail_path'] = get_attached_file($data['thumbnail_id']);
                 // Thumbnail (full img tag)
                 if (apply_filters('wpo_wcpdf_use_path', true)) {
                     // load img with server path by default
                     $data['thumbnail'] = sprintf('<img width="90" height="90" src="%s" class="attachment-shop_thumbnail wp-post-image">', $data['thumbnail_path']);
                 } else {
                     // load img with http url when filtered
                     $data['thumbnail'] = $product->get_image('shop_thumbnail', array('title' => ''));
                 }
                 // Set the single price (turned off to use more consistent calculated price)
                 // $data['single_price'] = woocommerce_price ( $product->get_price() );
                 // Set item SKU
                 $data['sku'] = $product->get_sku();
                 // Set item weight
                 $data['weight'] = $product->get_weight();
                 // Set item dimensions
                 $data['dimensions'] = $product->get_dimensions();
                 // Pass complete product object
                 $data['product'] = $product;
             }
             $data_list[] = apply_filters('wpo_wcpdf_order_item_data', $data);
         }
     }
     return apply_filters('wpo_wcpdf_order_items_data', $data_list);
 }