_e('Product', 'woocommerce');
?>
</th>
			<th class="product-quantity"><?php 
_e('Qty', 'woocommerce');
?>
</th>
			<th class="product-total"><?php 
_e('Totals', 'woocommerce');
?>
</th>
		</tr>
	</thead>
	<tfoot>
	<?php 
if ($totals = $order->get_order_item_totals()) {
    foreach ($totals as $label => $value) {
        ?>
			<tr>
				<th scope="row" colspan="2"><?php 
        echo $label;
        ?>
</th>
				<td><?php 
        echo $value;
        ?>
</td>
			</tr>
			<?php 
    }
}
global $woocommerce;

$order = new WC_Order( $order_id );
?>
<h5><?php _e('Order Details', 'woocommerce'); ?></h5>
<table class="shop_table order_details table table-bordered table-striped">
	<thead>
		<tr>
			<th class="product-name"><?php _e('Product', 'woocommerce'); ?></th>
			<th class="product-quantity"><?php _e('Qty', 'woocommerce'); ?></th>
			<th class="product-total"><?php _e('Totals', 'woocommerce'); ?></th>
		</tr>
	</thead>
	<tfoot>
	<?php
		if ( $totals = $order->get_order_item_totals() ) foreach ( $totals as $total ) :
			?>
			<tr>
				<th scope="row" colspan="2"><?php echo $total['label']; ?></th>
				<td><?php echo $total['value']; ?></td>
			</tr>
			<?php
		endforeach;
	?>
	</tfoot>
	<tbody>
		<?php
		if (sizeof($order->get_items())>0) :

			foreach($order->get_items() as $item) :
Exemple #3
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 
}
 /**
  * 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;
 }
function orderpost($orderId)
{
    global $wpdb;
    $testMode = get_option('linksync_test');
    $LAIDKey = get_option('linksync_laid');
    $apicall = new linksync_class($LAIDKey, $testMode);
    //Checking for already sent Order
    $sentOrderIds = get_option('linksync_sent_order_id');
    if (isset($sentOrderIds)) {
        if (!empty($sentOrderIds)) {
            $order_id_array = unserialize($sentOrderIds);
        } else {
            $order_id_array = array();
        }
        if (!in_array($orderId, $order_id_array)) {
            $order = new WC_Order($orderId);
            if ($order->post_status == get_option('order_status_wc_to_vend')) {
                update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId))));
                $order_no = $order->get_order_number();
                if (strpos($order_no, '#') !== false) {
                    $order_no = str_replace('#', '', $order_no);
                }
                $get_total = $order->get_total();
                $get_user = $order->get_user();
                $comments = $order->post->post_excerpt;
                $primary_email_address = $get_user->data->user_email;
                $currency = $order->get_order_currency();
                $shipping_method = $order->get_shipping_method();
                $order_total = $order->get_order_item_totals();
                $transaction_id = $order->get_transaction_id();
                $taxes_included = false;
                $total_discount = $order->get_total_discount();
                $total_quantity = 0;
                $registerDb = get_option('wc_to_vend_register');
                $vend_uid = get_option('wc_to_vend_user');
                $total_tax = $order->get_total_tax();
                // Geting Payment object details
                if (isset($order_total['payment_method']['value']) && !empty($order_total['payment_method']['value'])) {
                    $wc_payment = get_option('wc_to_vend_payment');
                    if (isset($wc_payment) && !empty($wc_payment)) {
                        $total_payments = explode(",", $wc_payment);
                        foreach ($total_payments as $mapped_payment) {
                            $exploded_mapped_payment = explode("|", $mapped_payment);
                            if (isset($exploded_mapped_payment[1]) && !empty($exploded_mapped_payment[1]) && isset($exploded_mapped_payment[0]) && !empty($exploded_mapped_payment[0])) {
                                if ($exploded_mapped_payment[1] == $order_total['payment_method']['value']) {
                                    $vend_payment_data = explode("%%", $exploded_mapped_payment[0]);
                                    if (isset($vend_payment_data[0])) {
                                        $payment_method = $vend_payment_data[0];
                                    }
                                    if (isset($vend_payment_data[1])) {
                                        $payment_method_id = $vend_payment_data[1];
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    $payment = array("retailer_payment_type_id" => isset($payment_method_id) ? $payment_method_id : null, "amount" => isset($get_total) ? $get_total : 0, "method" => isset($payment_method) ? $payment_method : null, "transactionNumber" => isset($transaction_id) ? $transaction_id : null);
                }
                $export_user_details = get_option('wc_to_vend_export');
                if (isset($export_user_details) && !empty($export_user_details)) {
                    if ($export_user_details == 'customer') {
                        //woocommerce filter
                        $billingAddress_filter = apply_filters('woocommerce_order_formatted_billing_address', array('firstName' => $order->billing_first_name, 'lastName' => $order->billing_last_name, 'phone' => $order->billing_phone, 'street1' => $order->billing_address_1, 'street2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postalCode' => $order->billing_postcode, 'country' => $order->billing_country, 'company' => $order->billing_company, 'email_address' => $order->billing_email), $order);
                        $billingAddress = array('firstName' => $billingAddress_filter['firstName'], 'lastName' => $billingAddress_filter['lastName'], 'phone' => $billingAddress_filter['phone'], 'street1' => $billingAddress_filter['street1'], 'street2' => $billingAddress_filter['street2'], 'city' => $billingAddress_filter['city'], 'state' => $billingAddress_filter['state'], 'postalCode' => $billingAddress_filter['postalCode'], 'country' => $billingAddress_filter['country'], 'company' => $billingAddress_filter['company'], 'email_address' => $billingAddress_filter['email_address']);
                        $deliveryAddress_filter = apply_filters('woocommerce_order_formatted_shipping_address', array('firstName' => $order->shipping_first_name, 'lastName' => $order->shipping_last_name, 'phone' => $order->shipping_phone, 'street1' => $order->shipping_address_1, 'street2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postalCode' => $order->shipping_postcode, 'country' => $order->shipping_country, 'company' => $order->shipping_company), $order);
                        $deliveryAddress = array('firstName' => $deliveryAddress_filter['firstName'], 'lastName' => $deliveryAddress_filter['lastName'], 'phone' => $deliveryAddress_filter['phone'], 'street1' => $deliveryAddress_filter['street1'], 'street2' => $deliveryAddress_filter['street2'], 'city' => $deliveryAddress_filter['city'], 'state' => $deliveryAddress_filter['state'], 'postalCode' => $deliveryAddress_filter['postalCode'], 'country' => $deliveryAddress_filter['country'], 'company' => $deliveryAddress_filter['company']);
                        $primary_email = isset($primary_email_address) ? $primary_email_address : $billingAddress['email_address'];
                        unset($billingAddress['email_address']);
                    }
                }
                $vend_user_detail = get_option('wc_to_vend_user');
                if (isset($vend_user_detail) && !empty($vend_user_detail)) {
                    $user = explode('|', $vend_user_detail);
                    $vend_uid = isset($user[0]) ? $user[0] : null;
                    $vend_username = isset($user[1]) ? $user[1] : null;
                }
                //Ordered product(s)
                $items = $order->get_items();
                $taxes = $order->get_taxes();
                foreach ($items as $item) {
                    foreach ($taxes as $tax_label) {
                        $sql = mysql_query("SELECT  tax_rate_id FROM  `" . $wpdb->prefix . "woocommerce_tax_rates` WHERE  tax_rate_name='" . $tax_label['label'] . "' AND tax_rate_class='" . $item['item_meta']['_tax_class'][0] . "'");
                        if (mysql_num_rows($sql) != 0) {
                            $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]);
                            if ($tax_classes['result'] == 'success') {
                                $vend_taxes = explode('/', $tax_classes['tax_classes']);
                            }
                        }
                    }
                    $taxId = isset($vend_taxes[0]) ? $vend_taxes[0] : null;
                    $taxName = isset($vend_taxes[1]) ? $vend_taxes[1] : null;
                    $taxRate = isset($vend_taxes[2]) ? $vend_taxes[2] : null;
                    if (isset($item['variation_id']) && !empty($item['variation_id'])) {
                        $product_id = $item['variation_id'];
                    } else {
                        $product_id = $item['product_id'];
                    }
                    $pro_object = new WC_Product($product_id);
                    $itemtotal = (double) $item['item_meta']['_line_subtotal'][0];
                    if (isset($item['line_subtotal']) && !empty($item['line_subtotal'])) {
                        $product_amount = (double) ($item['line_subtotal'] / $item['qty']);
                    }
                    $discount = (double) $item['item_meta']['_line_subtotal'][0] - (double) $item['item_meta']['_line_total'][0];
                    if (isset($discount) && !empty($discount)) {
                        $discount = (double) ($discount / $item['qty']);
                    }
                    #---------Changes--------#
                    //Product Amount = product org amount - discount amount
                    $product_total_amount = (double) $product_amount - (double) $discount;
                    $product_sku = $pro_object->get_sku();
                    if (isset($product_total_amount) && isset($taxRate) && !empty($product_total_amount) && !empty($taxRate)) {
                        $taxValue = $product_total_amount * $taxRate;
                    }
                    $products[] = array('sku' => $product_sku, 'title' => $item['name'], 'price' => $product_total_amount, 'quantity' => $item['qty'], 'discountAmount' => isset($discount) ? $discount : 0, 'taxName' => isset($taxName) ? $taxName : null, 'taxId' => isset($taxId) ? $taxId : null, 'taxRate' => isset($taxRate) ? $taxRate : null, 'taxValue' => isset($taxValue) ? $taxValue : null, 'discountTitle' => isset($discountTitle) ? $discountTitle : 'sale');
                    $total_quantity += $item['qty'];
                    unset($taxId);
                    unset($taxName);
                    unset($taxRate);
                    unset($taxValue);
                }
                #---------Discount-----#
                //              if (isset($total_discount) && !empty($total_discount)) {
                //                    $taxes_Discount = $apicall->linksync_getTaxes();
                //                    if (isset($taxes_Discount) && !empty($taxes_Discount)) {
                //                        if (!isset($taxes_Discount['errorCode'])) {
                //                            if (isset($taxes_Discount['taxes'])) {
                //                                foreach ($taxes_Discount['taxes'] as $select_tax) {
                //                                    if ($select_tax['name'] == 'GST') {
                //                                        $discountTaxName = $select_tax['name'];
                //                                        $discountTaxId = $select_tax['id'];
                //                                        $discountTaxRate = $select_tax['rate'];
                //                                    }
                //                                }
                //                            }
                //                        }
                //                    }
                //                    if (isset($total_discount)) {
                //                        if (isset($discountTaxRate) && !empty($discountTaxRate)) {
                //                            $taxValue_discount = $discountTaxRate * $total_discount;
                //                        }
                //                    }
                //                    $products[] = array(
                //                        "price" => isset($total_discount) ? $total_discount : null,
                //                        "quantity" => 1,
                //                        "sku" => "vend-discount",
                //                        'taxName' => isset($discountTaxName) ? $discountTaxName : null,
                //                        'taxId' => isset($discountTaxId) ? $discountTaxId : null,
                //                        'taxRate' => isset($discountTaxRate) ? $discountTaxRate : null,
                //                        'taxValue' => isset($taxValue_discount) ? $taxValue_discount : null
                //                    );
                //                    $products[] = array(
                //                        "price" => isset($total_discount) ? $total_discount : null,
                //                        "quantity" => 1,
                //                        "sku" => "vend-discount",
                //                        'taxName' => null,
                //                        'taxId' => null,
                //                        'taxRate' => null,
                //                        'taxValue' => null
                //                    );
                //            }
                #----------Shipping------------#
                foreach ($taxes as $tax_label) {
                    if (isset($tax_label['shipping_tax_amount']) && !empty($tax_label['shipping_tax_amount'])) {
                        $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]);
                        if ($tax_classes['result'] == 'success') {
                            $vend_taxes = explode('/', $tax_classes['tax_classes']);
                            $taxId_shipping = isset($vend_taxes[0]) ? $vend_taxes[0] : null;
                            $taxName_shipping = isset($vend_taxes[1]) ? $vend_taxes[1] : null;
                            $taxRate_shipping = isset($vend_taxes[2]) ? $vend_taxes[2] : null;
                        }
                    }
                }
                if (isset($shipping_method) && !empty($shipping_method)) {
                    $shipping_cost = $order->get_total_shipping();
                    $shipping_with_tax = $order->get_shipping_tax();
                    if ($shipping_with_tax > 0) {
                        if (isset($shipping_cost) && isset($taxRate_shipping) && !empty($shipping_cost) && !empty($taxRate_shipping)) {
                            $taxValue_shipping = $shipping_cost * $taxRate_shipping;
                        }
                    }
                    $products[] = array("price" => isset($shipping_cost) ? $shipping_cost : null, "quantity" => 1, "sku" => "shipping", 'taxName' => isset($taxName_shipping) ? $taxName_shipping : null, 'taxId' => isset($taxId_shipping) ? $taxId_shipping : null, 'taxRate' => isset($taxRate_shipping) ? $taxRate_shipping : null, 'taxValue' => isset($taxValue_shipping) ? $taxValue_shipping : null);
                }
                //UTC Time
                date_default_timezone_set("UTC");
                $order_created = date("Y-m-d H:i:s", time());
                $OrderArray = array('uid' => isset($vend_uid) ? $vend_uid : null, 'created' => isset($order_created) ? $order_created : null, "orderId" => isset($order_no) ? $order_no : null, "source" => "WooCommerce", 'register_id' => isset($registerDb) ? $registerDb : null, 'user_name' => isset($vend_username) ? $vend_username : null, 'primary_email' => isset($primary_email) && !empty($primary_email) ? $primary_email : null, 'total' => isset($get_total) ? $get_total : 0, 'total_tax' => isset($total_tax) ? $total_tax : 0, 'comments' => isset($comments) ? $comments : null, 'taxes_included' => $taxes_included, 'currency' => isset($currency) ? $currency : 'USD', 'shipping_method' => isset($shipping_method) ? $shipping_method : null, 'payment' => isset($payment) && !empty($payment) ? $payment : null, 'products' => isset($products) && !empty($products) ? $products : null, 'payment_type_id' => isset($payment_method_id) ? $payment_method_id : null, 'billingAddress' => isset($billingAddress) && !empty($billingAddress) ? $billingAddress : null, 'deliveryAddress' => isset($deliveryAddress) && !empty($deliveryAddress) ? $deliveryAddress : null);
                $json = json_encode($OrderArray);
                $apicall->linksync_postOrder($json);
                linksync_class::add('Order Sync Woo to Vend', 'success', 'Woo Order no:' . $order_no, $LAIDKey);
            }
        } else {
            linksync_class::add('Order Sync Woo to Vend', 'Error', 'Already Sent Order', $LAIDKey);
        }
    }
}
    public static function fp_rac_mail_admin_cart_recovered($order_id)
    {
        if (get_option('rac_admin_cart_recovered_noti') == "yes") {
            $to = get_option('rac_admin_email');
            $subject = get_option('rac_recovered_email_subject');
            $message = get_option('rac_recovered_email_message');
            $headers = "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
            if (get_option('rac_recovered_sender_opt') == "woo") {
                $headers .= FPRacCron::rac_formatted_from_address_woocommerce();
                $headers .= "Reply-To: " . get_option('woocommerce_email_from_name') . " <" . get_option('woocommerce_email_from_address') . ">\r\n";
            } else {
                $headers .= FPRacCron::rac_formatted_from_address_local(get_option('rac_recovered_from_name'), get_option('rac_recovered_from_email'));
                $headers .= "Reply-To: " . get_option('rac_recovered_from_name') . " <" . get_option('rac_recovered_from_email') . ">\r\n";
            }
            $message = str_replace('{rac.recovered_order_id}', $order_id, $message);
            //replacing shortcode for order id
            ob_start();
            $order = new WC_Order($order_id);
            ?>

            <table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
                <thead>
                    <tr>
                        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
            _e('Product', 'woocommerce');
            ?>
</th>
                        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
            _e('Quantity', 'woocommerce');
            ?>
</th>
                        <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php 
            _e('Price', 'woocommerce');
            ?>
</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
            echo $order->email_order_items_table(false, true);
            ?>

                </tbody>
                <tfoot>
                    <?php 
            if ($totals = $order->get_order_item_totals()) {
                $i = 0;
                foreach ($totals as $total) {
                    $i++;
                    ?>
<tr>
                                <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php 
                    if ($i == 1) {
                        echo 'border-top-width: 4px;';
                    }
                    ?>
"><?php 
                    echo $total['label'];
                    ?>
</th>
                                <td style="text-align:left; border: 1px solid #eee; <?php 
                    if ($i == 1) {
                        echo 'border-top-width: 4px;';
                    }
                    ?>
"><?php 
                    echo $total['value'];
                    ?>
</td>
                            </tr><?php 
                }
            }
            ?>

                </tfoot>
            </table>

            <?php 
            $newdata = ob_get_clean();
            ob_start();
            $message = str_replace('{rac.order_line_items}', $newdata, $message);
            if (function_exists('wc_get_template')) {
                wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                echo $message;
                wc_get_template('emails/email-footer.php');
            } else {
                woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                echo $message;
                woocommerce_get_template('emails/email-footer.php');
            }
            $woo_temp_msg = ob_get_clean();
            if ('wp_mail' == get_option('rac_trouble_mail')) {
                FPRacCron::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers);
            } else {
                FPRacCron::rac_send_mail($to, $subject, $woo_temp_msg, $headers);
            }
        }
    }