function generate_financials_csv($export_event_id)
{
    $orders = TribeEventsTickets::get_event_attendees($export_event_id);
    $counter = 1;
    $export_financials = array();
    $temp_order_id = 0;
    $temp_product_id = 0;
    $temp_counter = 1;
    foreach ($orders as $order) {
        $number = $counter;
        $order_id = $order['order_id'];
        $order_meta = get_post_meta($order_id);
        $temp_product_id = $order['product_id'];
        $ticket = $order['ticket'];
        $purchase_date = get_the_date('F j, Y g:i a', $order_id);
        // $order_meta['_paid_date'][0];
        $purchaser_name = $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0];
        $user_id = $order_meta['_customer_user'][0];
        $purchaser_email = $order_meta['_billing_email'][0];
        $purchaser_phone = $order_meta['_billing_phone'][0];
        $company = $order_meta['_billing_company'][0];
        $address1 = $order_meta['_billing_address_1'][0];
        $address2 = $order_meta['_billing_address_2'][0];
        $address = $address1 . ', ' . $address2;
        $city = $order_meta['_billing_city'][0];
        $state = $order_meta['_billing_state'][0];
        $zip = $order_meta['_billing_postcode'][0];
        $discount = round($order_meta['_cart_discount'][0], 2);
        $total = $order_meta['_order_total'][0];
        $payment_method = $order_meta['_payment_method_title'][0];
        if ($temp_order_id == $order_id && $temp_product_id == $order['product_id']) {
            $temp_counter++;
        } else {
            $temp_counter = 1;
        }
        $attendee_first_name = $order_meta["attendee_first_name_" . $temp_product_id . "_" . $temp_counter][0];
        if (empty($attendee_first_name)) {
            $attendee_first_name = $order_meta["attendee_name_" . $temp_product_id . "_" . $temp_counter][0];
        }
        $attendee_last_name = $order_meta["attendee_last_name_" . $temp_product_id . "_" . $temp_counter][0];
        $attendee_job = $order_meta["attendee_job_title_" . $temp_product_id . "_" . $temp_counter][0];
        $attendee_phone = $order_meta["attendee_primary_phone_" . $temp_product_id . "_" . $temp_counter][0];
        $order_cst = new WC_Order($order_id);
        $order_items = $order_cst->get_items();
        foreach ($order_items as $item_id => $values) {
            $attendee_count = $values['qty'];
            break;
        }
        $coupons = $order_cst->get_used_coupons();
        $coupon = $coupons[0];
        if (!$coupon) {
            $coupon = "";
        }
        if ($discount == 0) {
            $discount = "";
        } else {
            $discount = "\$" . $discount;
        }
        $export_financials[$counter] = array($order_id, $purchase_date, $ticket, $user_id, $purchaser_name, $purchaser_email, $purchaser_phone, $company, $address, $city, $state, $zip, $attendee_first_name, $attendee_last_name, $attendee_job, $attendee_cell_phone, $attendee_work_phone, $attendee_count, $total, $payment_method, $coupon, $discount);
        $counter++;
        $temp_order_id = $order_id;
        $temp_product_id = $order['product_id'];
    }
    $event = get_post($export_event_id);
    if (!empty($export_financials)) {
        $charset = get_option('blog_charset');
        $start_date = strtotime(get_post_meta($event, '_EventStartDate', true));
        $filename = $event->post_name;
        // output headers so that the file is downloaded rather than displayed
        header("Content-Type: text/csv; charset={$charset}");
        header("Content-Disposition: attachment; filename={$filename}-fiancial-data.csv");
        // create a file pointer connected to the output stream
        $output = fopen('php://output', 'w');
        fputcsv($output, array('Order ID', 'Purchase Date', 'Ticket Name', 'User ID', 'Purchaser Name', 'Purchaser Email', 'Purchaser Phone', 'Purchaser Company', 'Address', 'City', 'State', 'Zip', 'Attendee First Name', 'Attendee Last Name', 'Job Title', 'Cell Phone', 'Work Phone', 'Number of Tickets Purchased', 'Total Paid', 'Payment Method', 'Coupon Code', 'Discount Amount'));
        // And echo the data
        foreach ($export_financials as $item) {
            fputcsv($output, $item);
        }
        fclose($output);
        exit;
    }
}
function send_product_tag($order_id)
{
    $order = new WC_Order($order_id);
    $user = $order->billing_email;
    $items = $order->get_items();
    $coupons = $order->get_used_coupons();
    $traits = array('has_purchased' => 'yes');
    conveyour_identify($user, $traits);
    if (isset($coupons)) {
        foreach ($coupons as $coupon) {
            conveyour_track($user, 'used_coupon', array('coupon' => $coupon));
        }
    }
    foreach ($items as $item) {
        $product_name = $item['name'];
        $product_name_underscores = str_replace(' ', '_', $product_name);
        $product_name_sliced_and_underscored = substr($product_name_underscores, 0, 6);
        $myproduct_id = $item['product_id'];
        $my_product_name = $myproduct_id . '-' . $product_name_sliced_and_underscored;
        $product_object = new WC_Product($myproduct_id);
        $product_price = $product_object->regular_price;
        $traits = array('product' => $my_product_name, 'Item-Price' => $product_price, 'Order-ID' => $order_id);
        conveyour_track($user, 'Purchased_product', $traits);
    }
}
 public static function delete_rac_coupon($order_id)
 {
     if ('yes' === get_option('rac_delete_coupon_after_use')) {
         $order = new WC_Order($order_id);
         $used_coupons = $order->get_used_coupons();
         foreach ($used_coupons as $coupon) {
             $coupon_ob = new WC_Coupon($coupon);
             if (get_post_meta($coupon_ob->id, 'coupon_by_rac', true) == 'yes') {
                 wp_delete_post($coupon_ob->id, true);
             }
         }
     }
 }
Пример #4
0
/**
 * Bundle and format the order information
 * @param WC_Order $order
 * Send as much information about the order as possible to Conekta
 */
function getRequestData($order)
{
    if ($order and $order != null) {
        // custom fields
        $custom_fields = array("total_discount" => (double) $order->get_total_discount() * 100);
        // $user_id = $order->get_user_id();
        // $is_paying_customer = false;
        $order_coupons = $order->get_used_coupons();
        // if ($user_id != 0) {
        //     $custom_fields = array_merge($custom_fields, array(
        //         "is_paying_customer" => is_paying_customer($user_id)
        //     ));
        // }
        if (count($order_coupons) > 0) {
            $custom_fields = array_merge($custom_fields, array("coupon_code" => $order_coupons[0]));
        }
        return array("amount" => (double) $order->get_total() * 100, "token" => $_POST['conektaToken'], "shipping_method" => $order->get_shipping_method(), "shipping_carrier" => $order->get_shipping_method(), "shipping_cost" => (double) $order->get_total_shipping() * 100, "monthly_installments" => (int) $_POST['monthly_installments'], "currency" => strtolower(get_woocommerce_currency()), "description" => sprintf("Charge for %s", $order->billing_email), "card" => array_merge(array("name" => sprintf("%s %s", $order->billing_first_name, $order->billing_last_name), "address_line1" => $order->billing_address_1, "address_line2" => $order->billing_address_2, "billing_company" => $order->billing_company, "phone" => $order->billing_phone, "email" => $order->billing_email, "address_city" => $order->billing_city, "address_zip" => $order->billing_postcode, "address_state" => $order->billing_state, "address_country" => $order->billing_country, "shipping_address_line1" => $order->shipping_address_1, "shipping_address_line2" => $order->shipping_address_2, "shipping_phone" => $order->shipping_phone, "shipping_email" => $order->shipping_email, "shipping_address_city" => $order->shipping_city, "shipping_address_zip" => $order->shipping_postcode, "shipping_address_state" => $order->shipping_state, "shipping_address_country" => $order->shipping_country), $custom_fields));
    }
    return false;
}
 public function get_iframe_html($order_id = 0, $args = array())
 {
     $order = new WC_Order($order_id);
     $items = $order->get_items();
     $item_query_args = array();
     /**
      * Get total order level discount and then get average discount splitting it across all products.
      */
     // coupons
     $coupons = '';
     foreach ($order->get_used_coupons() as $coupon) {
         $item_query_args['COUPON'] .= $coupon;
     }
     $i = 0;
     foreach ($items as $item) {
         $i++;
         /**
          * Only add the product to the query arg if the data is valid
          */
         if (isset($item['product_id']) || 0 < absint($item['product_id'])) {
             $id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
             /**
              * Set the unique product ID
              */
             $item_query_args['ITEM_ID' . $i] = $id;
             /**
              * Get the product QTY
              */
             $item_query_args['QUANTITY' . $i] = isset($item['qty']) ? absint($item['qty']) : 0;
             /**
              * Get the product total, and deduct the average item discount from it.
              * absint() should always give us a number greater or equal to zero.
              */
             $item_query_args['ITEM_PRICE' . $i] = 0 < $total ? number_format($total, 2, '.', '') : 0;
         }
     }
     $src = $this->generate_iframe_src($order_id, $item_query_args);
     return '<iframe src="' . $src . '" width="1" height="1" frameborder="0"></iframe>';
 }
Пример #6
0
 public function get_coupon_by_user()
 {
     global $woocommerce;
     DABBA_API_Catch_Request::get()->check_params(array('user_id'));
     $args = array('numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $_POST['user_id'], 'post_type' => 'shop_order', 'post_status' => 'publish');
     $customer_orders = get_posts($args);
     $coupons_user = array();
     if ($customer_orders) {
         foreach ($customer_orders as $customer_order) {
             $order = new WC_Order($customer_order->ID);
             $couponR = $order->get_used_coupons();
             if ($couponR) {
                 foreach ($couponR as $singleCoupon) {
                     $coupon = new WC_Coupon($singleCoupon);
                     $order_info = array('order_id' => $order->id, "order_date" => $order->order_date, "total" => $order->get_total(), "status" => $order->get_status(), "items" => $order->get_items(), "payment_method" => $order->payment_method, "billing_address" => $order->get_address('billing'), "shipping_address" => $order->get_address('shipping'));
                     $coupons_user[] = array('order' => $order_info, 'coupon' => $coupon);
                 }
             }
         }
     }
     DABBA_API_Output::get()->output(true, 200, '', $coupons_user);
 }
    /**
     * Output the order tracking code for link connector
     *
     * @param WC_Order $order
     *
     * @return string
     */
    public function output_impact_radius_order_code($order)
    {
        if (!$this->impact_radius_src) {
            return;
        }
        $code = '<script src="https://' . $this->impact_radius_src . '"></script>';
        $code .= '<script>/* <![CDATA[ */
    irEvent.setOrderId("' . esc_js($order->get_order_number()) . '");';
        if ($order->get_items()) {
            foreach ($order->get_items() as $item) {
                $_product = $order->get_product_from_item($item);
                $categories = get_the_terms($_product->id, 'product_cat');
                $category = $categories ? $category[0]->name : '';
                $sku = $_product->get_sku() ? $_product->get_sku() : $_product->id;
                $code .= '
    irEvent.addItem("' . esc_js($category) . '", "' . esc_js($sku) . '", "' . esc_js($order->get_item_total($item)) . '", "' . esc_js($item['qty']) . '");';
            }
        }
        $coupons = $order->get_used_coupons();
        $coupon = $coupons ? $coupons[0] : '';
        $code .= '
    irEvent.setPromoCode("' . esc_js($coupon) . '");
    irEvent.fire();
/* ]]> */</script>';
        echo $code;
    }
 }
 echo "\nUSER ID : ";
 var_dump($user_id);
 echo "\n";
 if ($user_id instanceof WP_Error) {
     $temp_log_str = "\nUser could not be created. Invalid Email. So order could not be migrated ...\n";
     $log_str .= $temp_log_str;
     echo $temp_log_str;
     continue;
 }
 // Prepare Products array & cart array for the order.
 $downloads = array();
 $cart_details = array();
 $wc_items = $order->get_items();
 // Decide whether any coupon is used for discount or not.
 $wc_coupon = $order->get_used_coupons();
 if (!empty($wc_coupon)) {
     $wc_coupon = new WC_Coupon($wc_coupon[0]);
 } else {
     $wc_coupon = null;
 }
 // Line Items from the WC Order
 foreach ($wc_items as $item) {
     $product = $order->get_product_from_item($item);
     $item['quantity'] = $item['qty'];
     $item['data'] = $product;
     if (!isset($wc_edd_product_map[$product->id]) || empty($wc_edd_product_map[$product->id])) {
         $temp_log_str = "\nEDD Product Not available for this WC Product.\n";
         $log_str .= $temp_log_str;
         echo $temp_log_str;
         $break_loop = true;
Пример #9
0
 private function batchInvoice()
 {
     $json = file_get_contents('php://input');
     $json = json_decode($json);
     $invoices = array();
     try {
         if (!property_exists($json, 'customers')) {
             throw new GenericException('Invalid JSON request');
         }
         foreach ($json->customers as $customer) {
             if (!property_exists($customer, 'email')) {
                 continue;
             }
             if (email_exists($customer->email)) {
                 $invoice = new Invoice();
                 $invoice->setEmail($customer->email);
                 $orderPosts = get_posts(array('meta_key' => '_billing_email', 'meta_value' => $customer->email, 'post_type' => 'shop_order', 'numberposts' => -1));
                 foreach ($orderPosts as $post) {
                     $wpOrder = new WC_Order($post->ID);
                     if ($wpOrder->order_date > $customer->from && $wpOrder->order_date < $customer->to) {
                         $total = 0.0;
                         $tax = 0.0;
                         $count = 0;
                         $order = new Order();
                         foreach ($wpOrder->get_items('line_item') as $lineItem) {
                             $tax += (double) $lineItem['line_tax'];
                             $total += (double) $lineItem['line_total'] - (double) $lineItem['line_tax'];
                             $count++;
                             if ($lineItem->tax_class) {
                                 $order->setCurrency($lineItem['tax_class']);
                             }
                         }
                         $order->setId($wpOrder->id)->setDate(new \DateTime($wpOrder->order_date))->setItemCount($count)->setTotal($total, $tax);
                         $coupons = $wpOrder->get_used_coupons();
                         if (!empty($coupons)) {
                             $order->setCoupon($coupons[0]);
                         }
                         $invoice->addOrder($order);
                     }
                 }
                 $invoices[] = $invoice;
             }
         }
     } catch (GenericException $e) {
         $this->app['logger']->error($e);
     }
     $presenter = new BatchInvoicePresenter($invoices);
     wp_send_json($presenter->toArray());
 }
    public static function fp_rac_adandoncart_admin_display()
    {
        global $wpdb;
        $array = array();
        $table_name = $wpdb->prefix . 'rac_abandoncart';
        $count_trashed = 0;
        $new = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('trash')", ARRAY_A);
        $count_trashed = count($new);
        $new1 = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status NOT IN('trash')", ARRAY_A);
        $count_all = count($new1);
        $post_from_date = "";
        $post_to_date = "";
        if (!isset($_GET['section'])) {
            if (isset($_POST['filter_by_date'])) {
                $post_from_date = $_POST['rac_from_date'];
                $post_to_date = $_POST['rac_to_date'];
                $fromdate = strtotime($post_from_date . ' 00:00:00');
                $todate = strtotime($post_to_date . ' 23:59:59');
                if ($post_from_date != "" && $post_to_date != "") {
                    $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_abandon_time <={$todate} AND cart_status NOT IN('trash')", OBJECT);
                    $abandon_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_abandon_time <={$todate} AND cart_status IN('ABANDON')", OBJECT));
                    $new_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_abandon_time <={$todate} AND cart_status IN('NEW')", OBJECT));
                    $recovered_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_abandon_time <={$todate} AND cart_status IN('RECOVERED')", OBJECT));
                } elseif ($post_from_date != "" && $post_to_date == "") {
                    $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_status NOT IN('trash')", OBJECT);
                    $abandon_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_status IN('ABANDON')", OBJECT));
                    $new_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_status IN('NEW')", OBJECT));
                    $recovered_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time >={$fromdate} AND cart_status IN('RECOVERED')", OBJECT));
                } elseif ($post_from_date == "" && $post_to_date != "") {
                    $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time <={$todate} AND cart_status NOT IN('trash')", OBJECT);
                    $abandon_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time <={$todate} AND cart_status IN('ABANDON')", OBJECT));
                    $new_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time <={$todate} AND cart_status IN('NEW')", OBJECT));
                    $recovered_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_abandon_time <={$todate} AND cart_status IN('RECOVERED')", OBJECT));
                } else {
                    $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status NOT IN('trash')", OBJECT);
                    $abandon_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('ABANDON')", OBJECT));
                    $new_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('NEW')", OBJECT));
                    $recovered_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('RECOVERED')", OBJECT));
                }
            } else {
                $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status NOT IN('trash')", OBJECT);
                $abandon_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('ABANDON')", OBJECT));
                $new_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('NEW')", OBJECT));
                $recovered_count = count($wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('RECOVERED')", OBJECT));
            }
        } else {
            if ($_GET['section'] == 'trash') {
                $abandon_cart_list = $wpdb->get_results("SELECT * FROM {$table_name} WHERE cart_status IN('trash')", OBJECT);
            }
        }
        echo '&nbsp<span><select id="rac_pagination_cart">';
        for ($k = 1; $k <= 20; $k++) {
            if ($k == 10) {
                echo '<option value="' . $k . '" selected="selected">' . $k . '</option>';
            } else {
                echo '<option value="' . $k . '">' . $k . '</option>';
            }
        }
        echo '</select></span>';
        echo '&nbsp<label>Search</label><input type="text" name="rac_temp_search" id="rac_temp_search">';
        ?>

        <br>
        <br>
        <a href="<?php 
        echo esc_url_raw(remove_query_arg('section', get_permalink()));
        ?>
"><?php 
        _e("All ", 'recoverabandoncart');
        ?>
</a><?php 
        echo "({$count_all})";
        ?>

        |
        <a href="<?php 
        echo esc_url_raw(add_query_arg('section', 'trash', get_permalink()));
        ?>
"><?php 
        _e("Trash ", 'recoverabandoncart');
        ?>
</a><?php 
        echo "({$count_trashed})";
        ?>

        <style type="text/css">
            .rac_tool_info .tooltip {
                background: #1496bb;
                color: #fff;
                opacity: 0;
            }
            /* .rac_tool_info:hover .tooltip {
                opacity: 1;
            }*/

        </style>
        <script type='text/javascript'>
            jQuery(function () {
                jQuery('.rac_tool_info:not(.rac_content_get)').tipTip({'content': 'Click here to Edit Email ID for Guest'});
            });
        </script>
        <?php 
        if (!isset($_GET['section'])) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="fromDate">From date:</label> <input type="text"  class="rac_date" id="rac_from_date"  name="rac_from_date" value="' . $post_from_date . '" />';
            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="toDate">To date:</label> <input type="text" class="rac_date" id="rac_to_date" name="rac_to_date" value="' . $post_to_date . '" />';
            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="filter_by_date button-primary" id="filter_by_date" name="filter_by_date" value=" Filter " />';
            if (isset($_POST['filter_by_date'])) {
                echo '<br> Results by Date Filter<br>' . ' All (' . count($abandon_cart_list) . ')&nbsp';
                echo ' Abandon (' . $abandon_count . ')&nbsp';
                echo ' New (' . $new_count . ')&nbsp';
                echo ' Recovered (' . $recovered_count . ')';
            }
        }
        echo '<table class="rac_email_template_table_abandon table" data-page-size="10" data-filter="#rac_temp_search" data-filter-minimum="1">';
        echo '<thead>
		<tr>
			<th data-type="numeric">' . __('ID', 'recoverabandoncart') . '</th>
			<th data-hide="phone">' . __('Cart Details / Cart Total', 'recoverabandoncart') . '</th>
			<th>' . __('UserName / First Last Name', 'recoverabandoncart') . '</th>
                        <th>' . __('Email ID / Phone Number', 'recoverabandoncart') . '</th>
                        <th data-type="numeric">' . __('Abandoned Date/Time', 'recoverabandoncart') . '</th>
                        <th>' . __('Status', 'recoverabandoncart') . '</th>
                        <th>' . __('Email Template / Email Status / Cart Link in Email', 'recoverabandoncart') . '</th>
                        <th data-type="numeric">' . __('Recovered Order ID', 'recoverabandoncart') . '</th>
                        <th >' . __('Coupon Used', 'recoverabandoncart') . '</th>
                        <th >' . __('Payment Status', 'recoverabandoncart') . '</th>
                        <th>' . __('Mail Sending', 'recoverabandoncart') . '</th>';
        $main_trash_data = 'trash';
        // Check the Status
        if (!isset($_GET['section'])) {
            $main_trash_data = 'trash';
        } else {
            if ($_GET['section'] == 'trash') {
                $main_trash_data = 'permanent';
            }
        }
        echo '<th class="rac_small_col" data-sort-ignore="true"><a href="#" id="rac_page_select">' . __('Page Select', 'recoverabandoncart') . '</a>&nbsp/&nbsp<a href="#" id="rac_page_deselect">' . __('Page Deselct', 'recoverabandoncart') . '</a>&nbsp</br>&nbsp<a href="#" id="rac_sel">' . __('Select All', 'recoverabandoncart') . '</a>&nbsp/&nbsp <a href="#" id="rac_desel">' . __('Deselct All', 'recoverabandoncart') . '</a>&nbsp' . '<a href="#" class="rac_selected_del button" data-deletion=' . $main_trash_data . '>' . __('Delete Selected', 'recoverabandoncart') . '</a>&nbsp';
        if (!isset($_GET['section'])) {
            echo '<a href="#" id="rac_selected_mail" class="button button-primary">' . __('Send Mail for Selected', 'recoverabandoncart') . '</a>';
        } else {
            ?>

            <a href="#" class="rac_selected_del button" data-deletion="restore"><?php 
            echo "Restore Selected";
            ?>
</a>
            <?php 
        }
        echo '</th>
		</tr>
	</thead>';
        ?>

        <tbody>
            <?php 
        foreach ($abandon_cart_list as $each_list) {
            ?>

                <tr>
                    <td data-value="<?php 
            echo $each_list->id;
            ?>
"><?php 
            echo $each_list->id;
            ?>
</td>
                    <!--<td><?php 
            $each_list->cart_details;
            ?>
</td> -->
                    <td><?php 
            $cart_array = maybe_unserialize($each_list->cart_details);
            $total = '';
            if (is_array($cart_array) && is_null($each_list->ip_address)) {
                foreach ($cart_array as $cart) {
                    foreach ($cart as $inside) {
                        foreach ($inside as $product) {
                            $total += $product['line_subtotal'];
                            echo get_the_title($product['product_id']) . '<br>';
                        }
                    }
                }
                echo " / " . FP_List_Table_RAC::format_price($total);
            } elseif (is_array($cart_array)) {
                //for cart captured at checkout(GUEST)
                $first_name = $cart_array['first_name'];
                $last_name = $cart_array['last_name'];
                $guest_first_last = " / {$first_name} {$last_name}";
                unset($cart_array['visitor_mail']);
                unset($cart_array['first_name']);
                unset($cart_array['last_name']);
                if (isset($cart_array['visitor_phone'])) {
                    unset($cart_array['visitor_phone']);
                }
                foreach ($cart_array as $product) {
                    $total += $product['line_subtotal'];
                    echo get_the_title($product['product_id']) . '<br>';
                }
                echo " / " . FP_List_Table_RAC::format_price($total);
            } elseif (is_object($cart_array)) {
                // For Guest
                //var_dump($cart_array);
                foreach ($cart_array->get_items() as $item) {
                    $total += $item['line_subtotal'];
                    echo $item['name'] . '<br>';
                }
                echo " / " . FP_List_Table_RAC::format_price($total);
                $guest_first_last = " / {$cart_array->billing_first_name} {$cart_array->billing_last_name}";
            }
            ?>
</td>
                    <td><?php 
            $user_info = get_userdata($each_list->user_id);
            if (is_object($user_info)) {
                echo $user_info->user_login;
                echo " / {$user_info->user_firstname} {$user_info->user_lastname}";
            } elseif ($each_list->user_id == '0') {
                echo 'Guest';
                echo $guest_first_last;
            } elseif ($each_list->user_id == 'old_order') {
                $old_order_cart_ob = maybe_unserialize($each_list->cart_details);
                $user_inf = get_userdata($old_order_cart_ob->user_id);
                if (is_object($user_inf)) {
                    echo $user_inf->user_login;
                    echo " / {$user_inf->user_firstname} {$user_inf->user_lastname}";
                } else {
                    echo 'Guest';
                    echo $guest_first_last;
                }
            }
            ?>
</td>
                    <td>
                        <?php 
            if ('0' == $each_list->user_id) {
                $details = maybe_unserialize($each_list->cart_details);
                if (is_object($details)) {
                    ?>
 <div class="rac_tool_info"><p class="rac_edit_option" data-id="<?php 
                    echo $each_list->id;
                    ?>
" >
                                <?php 
                    echo $details->billing_email;
                    // Order Object. Works for both old order and rac captured order
                    ?>
</p><div class="tooltip">Double Click to Change an Editable</div></div><?php 
                    echo '</br>&nbsp' . $details->billing_phone;
                } elseif (is_array($details)) {
                    ?>
<div class="rac_tool_info"><p class="rac_edit_option" data-id="<?php 
                    echo $each_list->id;
                    ?>
">
                                        <?php 
                    // echo $each_list->email_id; //checkout order
                    echo $details['visitor_mail'];
                    //checkout order
                    ?>
</p><div class="tooltip">Double Click to Change an Editable</div></div><?php 
                    echo "</br>&nbsp";
                    if (isset($details['visitor_phone'])) {
                        echo $details['visitor_phone'];
                    } else {
                        echo '-';
                    }
                }
            } elseif ($each_list->user_id == 'old_order') {
                $old_order_cart_ob = maybe_unserialize($each_list->cart_details);
                $user_inf = get_userdata($old_order_cart_ob->user_id);
                if (is_object($user_inf)) {
                    echo $user_inf->user_email;
                    echo " / {$user_inf->billing_phone}";
                } else {
                    echo 'Guest';
                    //var_dump($old_order_cart_ob);
                    if (isset($old_order_cart_ob->billing_email)) {
                        echo " /" . $old_order_cart_ob->billing_email;
                    } else {
                        echo '-';
                    }
                }
            } else {
                $user_infor = get_userdata($each_list->user_id);
                if (is_object($user_infor)) {
                    echo $user_infor->user_email;
                    echo '</br> &nbsp' . $user_infor->billing_phone;
                }
            }
            ?>

                    </td>
                    <td data-value="<?php 
            echo $each_list->cart_abandon_time;
            ?>
">
                        <?php 
            echo date(get_option('date_format'), $each_list->cart_abandon_time) . '/' . date(get_option('time_format'), $each_list->cart_abandon_time);
            ?>

                    </td>
                    <td><?php 
            echo $each_list->cart_status == 'trash' ? 'Trashed' : $each_list->cart_status;
            ?>
</td>
                    <td>
                        <?php 
            $mail_sent = maybe_unserialize($each_list->mail_template_id);
            $email_table_name_clicked = $wpdb->prefix . 'rac_templates_email';
            $email_template_all = $wpdb->get_results("SELECT * FROM {$email_table_name_clicked}");
            foreach ($email_template_all as $check_all_email_temp) {
                echo $check_all_email_temp->template_name;
                //Mail Sent
                if (!is_null($mail_sent)) {
                    if (in_array($check_all_email_temp->id, (array) $mail_sent)) {
                        echo ' / Email Sent';
                    } else {
                        echo ' / Email Not Sent';
                    }
                } else {
                    echo ' / Email Not Sent';
                }
                //Mail Sent END
                //Link Clicked
                if (!empty($each_list->link_status)) {
                    $mails_clicked = maybe_unserialize($each_list->link_status);
                    if (in_array($check_all_email_temp->id, (array) $mails_clicked)) {
                        //  echo $check_all_email_temp->template_name;
                        echo ' / Cart Link Clicked';
                        echo '<br>';
                    } else {
                        // echo $check_all_email_temp->template_name;
                        echo ' / Cart Link Not Clicked';
                        echo '<br>';
                    }
                } else {
                    echo ' / Cart Link Not Clicked';
                    echo '<br>';
                }
                //Link Clicked END
            }
            ?>

                    </td>
                    <td data-value="<?php 
            echo $each_list->placed_order;
            ?>
"><?php 
            echo !is_null($each_list->placed_order) ? ' #' . $each_list->placed_order . '' : 'Not Yet';
            ?>
</td>
                    <td>
                        <?php 
            if ($each_list->cart_status == 'RECOVERED') {
                $coupon_code = get_option('abandon_time_of' . $each_list->id);
                $order = new WC_Order($each_list->placed_order);
                $coupons_used = $order->get_used_coupons();
                if (!empty($coupons_used)) {
                    if (in_array($coupon_code, $order->get_used_coupons())) {
                        echo $coupon_code . ' - ';
                        echo 'Succes';
                    } else {
                        echo 'Not Used';
                    }
                } else {
                    echo 'Not Used';
                }
            } else {
                echo 'Not Yet';
            }
            ?>

                    </td>
                    <td><?php 
            echo !empty($each_list->completed) ? 'Completed' : 'Not Yet';
            ?>
</td>
                    <td>
                        <?php 
            if ($each_list->cart_status != 'trash') {
                if (empty($each_list->completed)) {
                    //check if order completed,if completed don't show mail sending button'
                    ?>


                                <a href="#" class="button rac_mail_sending" data-racmoptid="<?php 
                    echo $each_list->id;
                    ?>
" data-currentsate="<?php 
                    echo $each_list->sending_status == 'SEND' ? 'SEND' : 'DONT';
                    ?>
"><?php 
                    if ($each_list->sending_status == 'SEND') {
                        echo 'Stop Mailing';
                    } else {
                        echo 'Start Mailing';
                    }
                    echo "</a>";
                } else {
                    echo 'Recovered';
                }
            } else {
                echo "Trashed";
            }
            ?>
</td>
                    <td class="bis_mas_small_col">
                        <input type="checkbox" class="rac_checkboxes" data-racid="<?php 
            echo $each_list->id;
            ?>
"/>
                        <a href="#" class="button rac_check_indi" data-deletion="<?php 
            echo $main_trash_data;
            ?>
" data-racdelid="<?php 
            echo $each_list->id;
            ?>
"><?php 
            echo $each_list->cart_status != 'trash' ? "Delete this Row" : "Delete Permanently";
            ?>
</a>
                        <?php 
            if ($each_list->cart_status == 'trash') {
                ?>

                            <a href="#" class="button rac_check_indi" data-deletion="restore" data-racdelid="<?php 
                echo $each_list->id;
                ?>
"><?php 
                _e('Restore', 'recoverabandoncart');
                ?>
</a>
                        <?php 
            }
            ?>

                    </td>
                </tr>
                <?php 
        }
        echo '</tbody>
            <tfoot>
		<tr>
			<td colspan="12">
				<div class="pagination pagination-centered hide-if-no-paging"></div>
			</td>
		</tr>
	</tfoot></table><style>.footable > tbody > tr > td,.footable > thead > tr > th, .footable > thead > tr > td{text-align:center;}</style>';
        ?>

        <script type="text/javascript">
            jQuery(document).ready(function () {
                //Manual Mail redirection
                jQuery('#rac_selected_mail').click(function (e) {
                    e.preventDefault();
                    var selection_for_mail = new Array();
                    jQuery('.rac_checkboxes').each(function (num) {
                        if (jQuery(this).prop('checked')) {
                            selection_for_mail.push(jQuery(this).data('racid'));
                        }
                    });
                    // console.log(jQuery('.bis_mas_checkboxes'));
                    console.log(selection_for_mail);
                    var url_without_data = "<?php 
        echo esc_url_raw(add_query_arg(array('page' => 'fprac_slug', 'tab' => 'fpracemail'), admin_url('admin.php')));
        ?>
";
                    var url_data = url_without_data + "&rac_send_email=" + selection_for_mail;
                    console.log(url_without_data);
                    console.log(url_data);
                    if (selection_for_mail.length > 0) {
                        window.location.replace(url_data);
                    } else {
                        alert("Select a row to mail");
                    }

                    //window.location.replace("<?php 
        echo add_query_arg(array('page' => 'fprac_slug', 'tab' => 'fpracemail', 'rac_send_email' => 'template'), admin_url('admin.php'));
        ?>
");
                });
            });

            //save editable table
            jQuery(document).ready(function () {
                jQuery(".rac_edit_option").dblclick(function (e) {
                    jQuery(this).next().remove();
                    jQuery(this).parent().removeAttr('class');


                    var p = jQuery(this).text();
                    var value = jQuery('<div class="raceditemail"><textarea class="rac_content_get" name="one" style="width:200px;height:100px;">' + p + '</textarea></br><input class="rac_save" type="button" value="save"/></div>');
                    var one = jQuery('.rac_content_get').val();
                    var id = jQuery(this).attr('data-id');

                    jQuery('.rac_content_get').parent().html(one);
                    //jQuery('.test').remove();
                    jQuery(this).empty();
                    jQuery(this).append(value);

                    jQuery(".rac_save").click(function () {
                        jQuery(".rac_save").prop("disabled", true);

                        var email = jQuery('.rac_content_get').val();
                        var data = {
                            action: "edit_value_update_now",
                            email: email,
                            id: id
                        }

                        jQuery.ajax({
                            type: "POST",
                            url: ajaxurl,
                            data: data
                        }).done(function (response) {
                            jQuery(".rac_save").prop("disabled", false);
                            var p = jQuery(this).text();
                            var value = jQuery('<div class="raceditemail"><textarea class="rac_content_get" name="one" style="width:200px;height:100px;">' + p + '</textarea></br><input class="rac_save" type="button" value="save"/></div>');
                            var one = jQuery('.rac_content_get').val();
                            var id = jQuery(this).attr('data-id');
                            jQuery('.rac_content_get').parent().html(one);
                            jQuery(this).parent().parent().parent().addClass('rac_tool_info');

                        });
                    });
                });
            });
        </script>

        <?php 
    }
    /**
     * Google Analytics eCommerce tracking
     *
     * @access public
     * @param mixed $order_id
     * @return void
     */
    function ecommerce_tracking_code($order_id)
    {
        global $woocommerce;
        if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1) {
            return;
        }
        $tracking_id = $this->ga_id;
        if (!$tracking_id) {
            return;
        }
        // Doing eCommerce tracking so unhook standard tracking from the footer
        remove_action("wp_footer", array($this, "ee_settings"));
        // Get the order and output tracking code
        $order = new WC_Order($order_id);
        //Get Applied Coupon Codes
        $coupons_list = '';
        if ($order->get_used_coupons()) {
            $coupons_count = count($order->get_used_coupons());
            $i = 1;
            foreach ($order->get_used_coupons() as $coupon) {
                $coupons_list .= $coupon;
                if ($i < $coupons_count) {
                    $coupons_list .= ', ';
                }
                $i++;
            }
        }
        //get domain name if value is set
        if (!empty($this->ga_Dname)) {
            $set_domain_name = esc_js($this->ga_Dname);
        } else {
            $set_domain_name = "auto";
        }
        //add display features
        if ($this->ga_DF) {
            $ga_display_feature_code = 'ga("require", "displayfeatures");';
        } else {
            $ga_display_feature_code = "";
        }
        //add Pageview on order page if user checked Add Standard UA code
        if ($this->ga_ST) {
            $ga_pageview = 'ga("send", "pageview");';
        } else {
            $ga_pageview = "";
        }
        $code = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
			(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
			m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
			})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
                        
			ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
                        ' . $ga_display_feature_code . '
			ga("require", "ec", "ec.js");
                        ' . $ga_pageview . '
                        ';
        // Order items
        if ($order->get_items()) {
            foreach ($order->get_items() as $item) {
                $_product = $order->get_product_from_item($item);
                if (isset($_product->variation_data)) {
                    $categories = esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
                } else {
                    $out = array();
                    $categories = get_the_terms($_product->id, "product_cat");
                    if ($categories) {
                        foreach ($categories as $category) {
                            $out[] = $category->name;
                        }
                    }
                    $categories = esc_js(join(",", $out));
                }
                //orderpage Prod json
                $orderpage_prod_Array[get_permalink($_product->id)] = array("tvc_id" => esc_html($_product->id), "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id), "tvc_n" => esc_js($item["name"]), "tvc_p" => esc_js($order->get_item_total($item)), "tvc_c" => $categories, "tvc_q" => esc_js($item["qty"]));
            }
            //make json for prod meta data on order page
            $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
        }
        //get shipping cost based on version >2.1 get_total_shipping() < get_shipping
        if (version_compare($woocommerce->version, "2.1", ">=")) {
            $tvc_sc = $order->get_total_shipping();
        } else {
            $tvc_sc = $order->get_shipping();
        }
        //orderpage transcation data json
        $orderpage_trans_Array = array("id" => esc_js($order->get_order_number()), "affiliation" => esc_js(get_bloginfo('name')), "revenue" => esc_js($order->get_total()), "tax" => esc_js($order->get_total_tax()), "shipping" => esc_js($tvc_sc), "coupon" => $coupons_list);
        //make json for trans data on order page
        $this->wc_version_compare("tvc_td=" . json_encode($orderpage_trans_Array) . ";");
        $code .= '
                //set local currencies
            ga("set", "&cu", tvc_lc);  
            for(var t_item in tvc_oc){
                ga("ec:addProduct", { 
                    "id": tvc_oc[t_item].tvc_i,
                    "name": tvc_oc[t_item].tvc_n, 
                    "category": tvc_oc[t_item].tvc_c,
                    "price": tvc_oc[t_item].tvc_p,
                    "quantity": tvc_oc[t_item].tvc_q,
			});
            }
            ga("ec:setAction","purchase", {
				"id": tvc_td.id,
				"affiliation": tvc_td.affiliation,
				"revenue": tvc_td.revenue,
                                "tax": tvc_td.tax,
				"shipping": tvc_td.shipping,
                                "coupon": tvc_td.coupon
			});
                        
        ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});      
    ';
        //check woocommerce version
        $this->wc_version_compare($code);
        update_post_meta($order_id, "_tracked", 1);
    }
 function coupons_used($order_id)
 {
     $order = new WC_Order($order_id);
     $email = get_post_meta($order_id, 'gift_receiver_email', true);
     /** this validation is not required
         * 
         * 
            if ( empty( $email ) || ! is_email( $email ) ) {
                    $email = $order->billing_email;
            }
         * 
         * 
         * **/
     if ($order->get_used_coupons()) {
         $this->update_coupons($order->get_used_coupons(), $email, '', 'remove');
     }
 }
Пример #13
0
function generate_attendee_csv($export_event_id)
{
    $all_attendees = TribeEventsTickets::get_event_attendees($export_event_id);
    $export_attendee_list = array();
    $counter = 0;
    $attendee_counter = 1;
    $old_order_id = 0;
    foreach ($all_attendees as $attendee) {
        $order_id = $attendee['order_id'];
        $order = new WC_Order($order_id);
        $order_meta = get_post_meta($order_id);
        $_product_id = $attendee['product_id'];
        // Purchaser Name
        $purchaser_name = $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0];
        // Company
        $company = $order_meta['_billing_company'][0];
        // Address
        $address1 = $order_meta['_billing_address_1'][0];
        $address2 = $order_meta['_billing_address_2'][0];
        $address = $address1 . ' ' . $address2;
        // City, State & Zip
        $city = $order_meta['_billing_city'][0];
        $state = $order_meta['_billing_state'][0];
        $zip = $order_meta['_billing_postcode'][0];
        // Email
        $purchaser_email = $order_meta['_billing_email'][0];
        // Amount paid
        $amt_paid = $order->get_formatted_order_total();
        $amt_paid = html_entity_decode(strip_tags($amt_paid), ENT_QUOTES, 'utf-8');
        // Reset the counter after each order
        if ($old_order_id == 0) {
            $old_order_id = $order_id;
        } else {
            if ($order_id != $old_order_id) {
                $attendee_counter = 1;
                $old_order_id = $order_id;
            }
        }
        // Attendee Name, Attendee Email, Job Title, Dietary Restrictions & Phone
        //$attendee_name                 = get_post_meta( $order_id, 'attendee_name_'.$_product_id.'_'.$attendee_counter, true);
        $attendee_first_name = get_post_meta($order_id, 'attendee_first_name_' . $_product_id . '_' . $attendee_counter, true);
        if (empty($attendee_first_name)) {
            $attendee_first_name = get_post_meta($order_id, 'attendee_name_' . $_product_id . '_' . $attendee_counter, true);
        }
        $attendee_last_name = get_post_meta($order_id, 'attendee_last_name_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_email = get_post_meta($order_id, 'attendee_email_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_job_title = get_post_meta($order_id, 'attendee_job_title_' . $_product_id . '_' . $attendee_counter, true);
        $attendee_dietary_restrictions = get_post_meta($order_id, 'attendee_dietary_restrictions_' . $_product_id . '_' . $attendee_counter, true);
        $phone = $order_meta['_billing_phone'][0];
        $discount = round($order_meta['_cart_discount'][0], 2);
        $coupons = $order->get_used_coupons();
        $coupon = $coupons[0];
        if (!$coupon) {
            $coupon = $discount = "";
        } else {
            $discount = "\$" . $discount;
        }
        $export_attendee_list[$counter] = array($purchaser_name, $phone, $company, $address, $city, $state, $zip, $purchaser_email, $amt_paid, $attendee_first_name, $attendee_last_name, $attendee_email, $attendee_company, $attendee_job_title, $attendee_dietary_restrictions, $attendee_cell_phone, $attendee_work_phone, $coupon, $discount);
        $counter++;
        $attendee_counter++;
    }
    $event = get_post($export_event_id);
    if (!empty($export_attendee_list)) {
        $charset = get_option('blog_charset');
        $start_date = strtotime(get_post_meta($event, '_EventStartDate', true));
        $filename = $event->post_name;
        // output headers so that the file is downloaded rather than displayed
        header("Content-Type: text/csv; charset={$charset}");
        header("Content-Disposition: attachment; filename={$filename}-attendees.csv");
        // create a file pointer connected to the output stream
        $output = fopen('php://output', 'w');
        fputcsv($output, array('Purchaser Name', 'Purchaser Phone', 'Purchaser Company', 'Address', 'City', 'State', 'Zip', 'Purchaser Email', 'Amount Paid', 'Attendee First Name', 'Attendee Last Name', 'Attendee Email', 'Attendee Company', 'Job Title', 'Dietary Restrictions', 'Cell Phone', 'Work Phone', 'Coupon Code', 'Coupon Amount'));
        foreach ($export_attendee_list as $item) {
            fputcsv($output, $item);
        }
        fclose($output);
        exit;
    }
}
Пример #14
0
/**
 * Check if an order has a coupon
 *
 * @param WC_Order $order
 * @param string $coupon_name
 * @return boolean
 */
function order_has_coupon(WC_Order $order, $coupon_name)
{
    if (!$order->get_used_coupons()) {
        return 0;
    }
    if (in_array($coupon_name, $order->get_used_coupons())) {
        return 1;
    }
}
/**
 * WooCommerce Extra Feature
 * --------------------------
 *
 * Send an email each time an order with coupon(s) is completed
 * The email contains coupon(s) used during checkout process
 *
 */
function woo_email_order_coupons($order_id)
{
    $order = new WC_Order($order_id);
    if ($order->get_used_coupons()) {
        $to = '*****@*****.**';
        $subject = 'New Coupon Order Completed';
        $headers = 'From: WOD Magazine <*****@*****.**>' . "\r\n";
        $message = 'A new order has been completed.\\n';
        $message .= 'Order ID: ' . $order_id . '\\n';
        $message .= 'Coupons used:\\n';
        foreach ($order->get_used_coupons() as $coupon) {
            $message .= $coupon . '\\n';
        }
        @wp_mail($to, $subject, $message, $headers);
    }
}
Пример #16
0
 /**
  * get vendor coupon from order.
  * @return boolean
  */
 function get_vendor_coupon_amount($item_product_id, $order_id, $vendor)
 {
     $order = new WC_Order($order_id);
     $coupons = $order->get_used_coupons();
     $coupon_used = array();
     if (!empty($coupons)) {
         foreach ($coupons as $coupon_code) {
             $coupon = new WC_Coupon($coupon_code);
             $coupon_post = get_post($coupon->id);
             $author_id = $coupon_post->post_author;
             if (get_current_user_id() != $author_id) {
                 continue;
             } else {
                 $coupon_product_ids = $coupon->product_ids;
                 if (!in_array($item_product_id, $coupon_product_ids)) {
                     continue;
                 } else {
                     $coupon_used[] = $coupon_code;
                 }
             }
         }
         if (!empty($coupon_used)) {
             $return_coupon = ' ,   Copoun Used : ';
             $no_of_coupon_use = false;
             foreach ($coupon_used as $coupon_use) {
                 if (!$no_of_coupon_use) {
                     $return_coupon .= '"' . $coupon_use . '"';
                 } else {
                     $return_coupon .= ', "' . $coupon_use . '"';
                 }
                 $no_of_coupon_use = true;
             }
             return $return_coupon;
         } else {
             return null;
         }
     }
 }
 public function save_order($order_id)
 {
     if (is_numeric($order_id) && $order_id > 0) {
         $order = new WC_Order($order_id);
         $coupons_list = '';
         if ($order->get_used_coupons()) {
             $coupons_count = count($order->get_used_coupons());
             $i = 1;
             foreach ($order->get_used_coupons() as $coupon) {
                 $coupons_list .= $coupon;
                 if ($i < $coupons_count) {
                     $coupons_list .= ', ';
                     $i++;
                 }
             }
         }
         $data = array('line_items' => array());
         foreach ((array) $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['item_meta'], $_product);
             if (apply_filters('woocommerce_order_item_visible', true, $item)) {
                 $line_item = array('id' => $item['product_id'], 'name' => $item['name'], 'price' => $item['line_subtotal'], 'quantity' => $item['qty'], 'variation_code' => $item['variation_id'] == 0 ? "" : $item['variation_id']);
             }
             $data['line_items'][] = $line_item;
         }
         echo '<script>
             var _ra = _ra || {};
             _ra.saveOrderInfo = {
                 "order_no": ' . $order->id . ',
                 "lastname": "' . $order->billing_last_name . '",
                 "firstname": "' . $order->billing_first_name . '",
                 "email": "' . $order->billing_email . '",
                 "phone": "' . $order->billing_phone . '",
                 "state": "' . $order->billing_state . '",
                 "city": "' . $order->billing_city . '",
                 "address": "' . $order->billing_address_1 . " " . $order->billing_address_2 . '",
                 "discount_code": "' . $coupons_list . '",
                 "discount": ' . (empty($order->get_discount) ? 0 : $order->get_discount) . ',
                 "shipping": ' . (empty($order->get_total_shipping) ? 0 : $order->get_total_shipping) . ',
                 "rebates": 0,
                 "fees": 0,
                 "total": ' . $order->order_total . '
             };
             _ra.saveOrderProducts =
                 ' . json_encode($data['line_items']) . '
             ;
             
             if( _ra.ready !== undefined ){
                 _ra.saveOrder(_ra.saveOrderInfo, _ra.saveOrderProducts);
             }
         </script>';
     }
     //REST API
     $orderInfo = array("order_no" => $order->id, "lastname" => $order->billing_last_name, "firstname" => $order->billing_first_name, "email" => $order->billing_email, "phone" => $order->billing_phone, "state" => $order->billing_state, "city" => $order->billing_city, "address" => $order->billing_address_1 . " " . $order->billing_address_2, "discount_code" => $coupons_list, "discount" => empty($order->get_discount) ? 0 : $order->get_discount, "shipping" => empty($order->get_total_shipping) ? 0 : $order->get_total_shipping, "total" => $order->order_total);
     if ($this->domain_api_key && $this->domain_api_key != "" && $this->token && $this->token != '') {
         $orderClient = new Retargeting_REST_API_Client($this->domain_api_key, $this->token);
         $orderClient->setResponseFormat("json");
         $orderClient->setDecoding(false);
         $response = $orderClient->order->save($orderInfo, $data['line_items']);
     }
 }
Пример #18
0
 function order_data($post_id)
 {
     global $wpdb;
     $WooCommerceNFe_Format = new WooCommerceNFe_Format();
     $order = new WC_Order($post_id);
     $coupons = $order->get_used_coupons();
     $coupons_percentage = array();
     $total_discount = 0;
     $data = array();
     if ($coupons) {
         foreach ($coupons as $coupon_code) {
             $coupon_obj = new WC_Coupon($coupon_code);
             if ($coupon_obj->discount_type == 'percent') {
                 $coupons_percentage[] = $coupon_obj->coupon_amount;
             }
         }
     }
     if ($order->get_fees()) {
         foreach ($order->get_fees() as $key => $item) {
             if ($item['line_total'] < 0) {
                 $discount = $item['line_total'] * -1;
                 $total_discount = $discount + $total_discount;
             } else {
                 $codigo_ean = get_option('wc_settings_woocommercenfe_ean');
                 $codigo_ncm = get_option('wc_settings_woocommercenfe_ncm');
                 $codigo_cest = get_option('wc_settings_woocommercenfe_cest');
                 $origem = get_option('wc_settings_woocommercenfe_origem');
                 $imposto = get_option('wc_settings_woocommercenfe_imposto');
                 $data['produtos'][] = array('nome' => $item['name'], 'sku' => $product->get_sku(), 'ean' => $codigo_ean, 'ncm' => $codigo_ncm, 'cest' => $codigo_cest, 'quantidade' => 1, 'unidade' => 'UN', 'peso' => '0.100', 'origem' => (int) $origem, 'subtotal' => number_format($item['line_subtotal'], 2), 'total' => number_format($item['line_total'], 2), 'classe_imposto' => $imposto);
             }
         }
     }
     $total_discount = $order->get_total_discount() + $total_discount;
     // Order
     $data = array('ID' => $post_id, 'operacao' => 1, 'natureza_operacao' => get_option('wc_settings_woocommercenfe_natureza_operacao'), 'modelo' => 1, 'emissao' => 1, 'finalidade' => 1, 'ambiente' => (int) get_option('wc_settings_woocommercenfe_ambiente'));
     $data['pedido'] = array('pagamento' => 0, 'presenca' => 2, 'modalidade_frete' => 0, 'frete' => get_post_meta($order->id, '_order_shipping', true), 'desconto' => $total_discount, 'total' => $order->order_total);
     //Informações COmplementares ao Fisco
     $fiscoinf = get_option('wc_settings_woocommercenfe_fisco_inf');
     if (!empty($fiscoinf) && strlen($fiscoinf) <= 2000) {
         $data['pedido']['informacoes_fisco'] = $fiscoinf;
     }
     //Informações Complementares ao Consumidor
     $consumidorinf = get_option('wc_settings_woocommercenfe_cons_inf');
     if (!empty($consumidorinf) && strlen($consumidorinf) <= 2000) {
         $data['pedido']['informacoes_complementares'] = $consumidorinf;
     }
     // Customer
     $tipo_pessoa = get_post_meta($post_id, '_billing_persontype', true);
     if (!$tipo_pessoa) {
         $tipo_pessoa = 1;
     }
     if ($tipo_pessoa == 1) {
         $data['cliente'] = array('cpf' => $WooCommerceNFe_Format->cpf(get_post_meta($post_id, '_billing_cpf', true)), 'nome_completo' => get_post_meta($post_id, '_billing_first_name', true) . ' ' . get_post_meta($post_id, '_billing_last_name', true), 'endereco' => get_post_meta($post_id, '_shipping_address_1', true), 'complemento' => get_post_meta($post_id, '_shipping_address_2', true), 'numero' => get_post_meta($post_id, '_shipping_number', true), 'bairro' => get_post_meta($post_id, '_shipping_neighborhood', true), 'cidade' => get_post_meta($post_id, '_shipping_city', true), 'uf' => get_post_meta($post_id, '_shipping_state', true), 'cep' => $WooCommerceNFe_Format->cep(get_post_meta($post_id, '_shipping_postcode', true)), 'telefone' => get_user_meta($post_id, 'billing_phone', true), 'email' => get_post_meta($post_id, '_billing_email', true));
     }
     if ($tipo_pessoa == 2) {
         $data['cliente'] = array('cnpj' => $WooCommerceNFe_Format->cnpj(get_post_meta($post_id, '_billing_cnpj', true)), 'razao_social' => get_post_meta($post_id, '_billing_company', true), 'ie' => get_post_meta($post_id, '_billing_ie', true), 'endereco' => get_post_meta($post_id, '_shipping_address_1', true), 'complemento' => get_post_meta($post_id, '_shipping_address_2', true), 'numero' => get_post_meta($post_id, '_shipping_number', true), 'bairro' => get_post_meta($post_id, '_shipping_neighborhood', true), 'cidade' => get_post_meta($post_id, '_shipping_city', true), 'uf' => get_post_meta($post_id, '_shipping_state', true), 'cep' => $WooCommerceNFe_Format->cep(get_post_meta($post_id, '_shipping_postcode', true)), 'telefone' => get_user_meta($post_id, 'billing_phone', true), 'email' => get_post_meta($post_id, '_billing_email', true));
     }
     // Products
     foreach ($order->get_items() as $key => $item) {
         $product_id = $item['product_id'];
         $variation_id = $item['variation_id'];
         $ignorar_nfe = get_post_meta($product_id, '_nfe_ignorar_nfe', true);
         if ($ignorar_nfe == 1 || $order->get_item_subtotal($item, false, false) == 0) {
             $data['pedido']['total'] -= $item['line_subtotal'];
             if ($coupons_percentage) {
                 foreach ($coupons_percentage as $percentage) {
                     $data['pedido']['total'] += $percentage / 100 * $item['line_subtotal'];
                     $data['pedido']['desconto'] -= $percentage / 100 * $item['line_subtotal'];
                 }
             }
             $data['pedido']['total'] = number_format($data['pedido']['total'], 2);
             $data['pedido']['desconto'] = number_format($data['pedido']['desconto'], 2);
             continue;
         }
         $emitir = apply_filters('emitir_nfe_produto', true, $product_id);
         if ($variation_id) {
             $emitir = apply_filters('emitir_nfe_produto', true, $variation_id);
         }
         if ($emitir) {
             $product = $order->get_product_from_item($item);
             // Vars
             $codigo_ean = get_post_meta($product_id, '_nfe_codigo_ean', true);
             $codigo_ncm = get_post_meta($product_id, '_nfe_codigo_ncm', true);
             $codigo_cest = get_post_meta($product_id, '_nfe_codigo_cest', true);
             $origem = get_post_meta($product_id, '_nfe_origem', true);
             $imposto = get_post_meta($product_id, '_nfe_classe_imposto', true);
             $peso = $product->get_weight();
             if (!$peso) {
                 $peso = '0.100';
             }
             if (!$codigo_ean) {
                 $codigo_ean = get_option('wc_settings_woocommercenfe_ean');
             }
             if (!$codigo_ncm) {
                 $codigo_ncm = get_option('wc_settings_woocommercenfe_ncm');
             }
             if (!$codigo_cest) {
                 $codigo_cest = get_option('wc_settings_woocommercenfe_cest');
             }
             if (!is_numeric($origem)) {
                 $origem = get_option('wc_settings_woocommercenfe_origem');
             }
             if (!$imposto) {
                 $imposto = get_option('wc_settings_woocommercenfe_imposto');
             }
             // Attributes
             $variacoes = '';
             foreach (array_keys($item['item_meta']) as $meta) {
                 if (strpos($meta, 'pa_') !== false) {
                     $atributo = $item[$meta];
                     $nome_atributo = str_replace('pa_', '', $meta);
                     $nome_atributo = $wpdb->get_var("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = '{$nome_atributo}'");
                     $valor = strtoupper($item[$meta]);
                     $variacoes .= ' - ' . strtoupper($nome_atributo) . ': ' . $valor;
                 }
             }
             $data['produtos'][] = array('nome' => $item['name'] . $variacoes, 'sku' => $product->get_sku(), 'ean' => $codigo_ean, 'ncm' => $codigo_ncm, 'cest' => $codigo_cest, 'quantidade' => $item['qty'], 'unidade' => 'UN', 'peso' => $peso, 'origem' => (int) $origem, 'subtotal' => number_format($order->get_item_subtotal($item, false, false), 2), 'total' => number_format($order->get_line_total($item, false, false), 2), 'classe_imposto' => $imposto);
         }
     }
     return $data;
 }
Пример #19
0
 public function rf_woocommerce_order_status_processing($order_id)
 {
     global $wpdb;
     $order = new WC_Order($order_id);
     $order_status = $order->status;
     $invite_email = $order->billing_email;
     $used_coupon = $order->get_used_coupons();
     if (isset($used_coupon[0])) {
         $used_coupon = $used_coupon[0];
     }
     // update referfriend data
     if ($used_coupon) {
         $result = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE post_title = '{$used_coupon}' AND post_type = 'shop_coupon'");
         $coupon_id = $result->ID;
         $result = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE post_title = '{$used_coupon}' AND post_type = 'mg_referfriend'");
         if (!empty($result)) {
             $rf_id = $result->ID;
             $expiry_date = get_post_meta($coupon_id, 'expiry_date');
             $product_ids = get_post_meta($coupon_id, 'product_ids');
             $usage_count = get_post_meta($coupon_id, 'usage_count');
             update_post_meta($rf_id, 'rf_expiry_date', $expiry_date[0]);
             update_post_meta($rf_id, 'rf_product_ids', $product_ids[0]);
             update_post_meta($rf_id, 'rf_usage', $usage_count[0]);
         }
     }
     // billing email is associated with any referral email
     $result = $wpdb->get_row("SELECT * FROM {$wpdb->postmeta} WHERE meta_value = '{$invite_email}' AND meta_key = 'rf_invite_email'");
     if (!empty($result)) {
         if ($a = $wpdb->get_row("SELECT * FROM {$wpdb->postmeta} WHERE meta_value = '{$invite_email}' AND meta_key = 'rf_invited_email'", OBJECT)) {
             return;
         }
         //$result = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_value = '$invite_email' AND meta_key = 'rf_invite_email'" );
         // track for used coupon
         add_post_meta($result->post_id, 'rf_invited_email', $invite_email);
         $result = $wpdb->get_row("SELECT * FROM {$wpdb->postmeta} WHERE post_id = '{$result->post_id}' AND meta_key = 'rf_reward_email'");
         if ($reward_email = $result->meta_value) {
             $coupon_id = $this->rf_create_coupon(null, 'Reward', 1);
             $coupon_value = get_post_meta($coupon_id, 'rf_coupon_amount');
             // Send mail
             $data = array('friend' => '', 'sponsor' => $reward_email, 'coupon_value' => $coupon_value[0], 'coupon' => get_the_title($coupon_id), 'affiliate_type' => 'email_invite');
             $subj = rf_mail_replace(get_option('rf_reward_email_subject'), $data);
             $body = rf_mail_replace(get_option('rf_reward_email_heading') . '<br>' . get_option('rf_reward_email_content'), $data);
             $headers = array('Content-Type: text/html; charset=UTF-8');
             $a = wp_mail($reward_email, $subj, $body, $headers);
         }
     } elseif (isset($_COOKIE['utm'])) {
         // check if emai has invited
         if ($wpdb->get_row("SELECT * FROM {$wpdb->postmeta} WHERE meta_value = '{$invite_email}' AND meta_key = 'rf_invite_email'", OBJECT)) {
             return;
         }
         $this->rf_create(null, 'Reward', 2);
         // for referrer
         //set the billing email is used to reward affiliate and can not be reward affiliate if user using this billing email to buy other time
         add_post_meta($order_id, 'rf_invited_email', $invite_email);
         //$this->rf_create( $order_id, 'Invite', 2 ); // for person who is referred
     }
 }
 /**
  *
  * Update order item product when changing booking dates
  *
  * @param int $order_id
  * @param array $posted - Order content
  *
  **/
 public function easy_booking_update_order_product($order_id, $posted)
 {
     $order = new WC_Order($order_id);
     $items = $order->get_items();
     if ($items) {
         foreach ($items as $item_id => $item) {
             $product = $order->get_product_from_item($item);
             if (!$product) {
                 continue;
             }
             $start = wc_get_order_item_meta($item_id, '_ebs_start_format');
             $end = wc_get_order_item_meta($item_id, '_ebs_end_format');
             $product_id = wc_get_order_item_meta($item_id, '_product_id');
             $variation_id = wc_get_order_item_meta($item_id, '_variation_id');
             $id = empty($variation_id) ? $product_id : $variation_id;
             // Is product bookable ?
             $is_bookable = get_post_meta($id, '_booking_option', true);
             if (!empty($start) && !empty($end) || isset($is_bookable) && $is_bookable === 'yes') {
                 if (class_exists('WC_Session')) {
                     $session_data = WC()->session->get_session_data();
                     $order_booking_session = !empty($session_data['order_booking_' . $item_id]) ? WC()->session->get('order_booking_' . $item_id) : '';
                 } else {
                     $order_booking_session = '';
                 }
                 $item_tax_class = $posted['order_item_tax_class'][$item_id];
                 $order_item['quantity'] = wc_get_order_item_meta($item_id, '_qty');
                 if (!empty($order_booking_session)) {
                     $start = $order_booking_session['start'];
                     $end = $order_booking_session['end'];
                     $start_date = $order_booking_session['start_date'];
                     $end_date = $order_booking_session['end_date'];
                     if ($order_booking_session['new_price']) {
                         $new_price = $order_booking_session['new_price'];
                         $subtotal_price = $new_price['subtotal'];
                         $total_price = $new_price['total'];
                     }
                     if (!empty($item_tax_class)) {
                         $tax_subtotal = isset($new_price['tax_subtotal']) ? $new_price['tax_subtotal'] : '';
                         $tax_total = isset($new_price['tax_total']) ? $new_price['tax_total'] : '';
                     }
                     wc_update_order_item_meta($item_id, '_ebs_start_format', $start);
                     wc_update_order_item_meta($item_id, '_ebs_end_format', $end);
                     wc_update_order_item_meta($item_id, '_ebs_start_display', $start_date);
                     wc_update_order_item_meta($item_id, '_ebs_end_display', $end_date);
                     WC()->session->set('order_booking_' . $item_id, '');
                 } else {
                     $order_item['tax_class'] = $item_tax_class;
                     $coupons = $order->get_used_coupons();
                     $item_prices = $this->easy_booking_get_booking_price($product, $item_id, $start, $end, $order_item, $coupons);
                     if ($item_prices) {
                         $subtotal_price = $item_prices['subtotal'];
                         $total_price = $item_prices['total'];
                     }
                     if (!empty($item_tax_class)) {
                         $tax_subtotal = isset($new_price['tax_subtotal']) ? $new_price['tax_subtotal'] : '';
                         $tax_total = isset($new_price['tax_total']) ? $new_price['tax_total'] : '';
                     }
                 }
                 // Update totals
                 if (isset($subtotal_price)) {
                     wc_update_order_item_meta($item_id, '_line_subtotal', wc_format_decimal($subtotal_price));
                 }
                 if (isset($total_price)) {
                     wc_update_order_item_meta($item_id, '_line_total', wc_format_decimal($total_price));
                 }
                 if (!empty($tax_subtotal)) {
                     wc_update_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal($tax_subtotal));
                 }
                 if (!empty($tax_total)) {
                     wc_update_order_item_meta($item_id, '_line_tax', wc_format_decimal($tax_total));
                 }
                 if (!empty($tax_subtotal) && !empty($tax_total)) {
                     wc_update_order_item_meta($item_id, '_line_tax_data', array('total' => $tax_total, 'subtotal' => $tax_subtotal));
                 }
                 do_action('easy_booking_update_order_product', $order, $item_id, $order_item);
             }
         }
     }
 }
 /**
  * Function to notifiy user about remaining balance in Store Credit in "Order Complete" email
  *
  * @param WC_Order $order
  * @param boolean $send_to_admin
  */
 public function show_store_credit_balance($order = false, $send_to_admin = false, $plain_text = false)
 {
     if ($send_to_admin) {
         return;
     }
     if (sizeof($order->get_used_coupons()) > 0) {
         $store_credit_balance = '';
         foreach ($order->get_used_coupons() as $code) {
             if (!$code) {
                 continue;
             }
             $coupon = new WC_Coupon($code);
             if ($coupon->discount_type == 'smart_coupon' && $coupon->amount > 0) {
                 $store_credit_balance .= '<li><strong>' . $coupon->code . '</strong> &mdash; ' . $this->wc_price($coupon->amount) . '</li>';
             }
         }
         if (!empty($store_credit_balance)) {
             echo "<br /><h3>" . __('Store Credit / Gift Card Balance', self::$text_domain) . ": </h3>";
             echo "<ul>" . $store_credit_balance . "</ul><br />";
         }
     }
 }
    public function save_order($order_id)
    {
        if (is_numeric($order_id) && $order_id > 0) {
            $order = new WC_Order($order_id);
            $coupons_list = '';
            if ($order->get_used_coupons()) {
                $coupons_count = count($order->get_used_coupons());
                $i = 1;
                foreach ($order->get_used_coupons() as $coupon) {
                    $coupons_list .= $coupon;
                    if ($i < $coupons_count) {
                        $coupons_list .= ', ';
                        $i++;
                    }
                }
            }
            $data = array('line_items' => array());
            foreach ((array) $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['item_meta'], $_product);
                if (apply_filters('woocommerce_order_item_visible', true, $item)) {
                    $line_item = array('id' => $item['product_id'], 'name' => $item['name'], 'price' => $item['line_subtotal'], 'quantity' => $item['qty'], 'variation_code' => $item['variation_id'] == 0 ? "" : $item['variation_id']);
                }
                $data['line_items'][] = $line_item;
            }
            echo '<script>
var _ra = _ra || {};
    _ra.saveOrderInfo = {
        "order_no": ' . $order->id . ',
        "lastname": "' . $order->billing_last_name . '",
        "firstname": "' . $order->billing_first_name . '",
        "email": "' . $order->billing_email . '",
        "phone": "' . $order->billing_phone . '",
        "state": "' . $order->billing_state . '",
        "city": "' . $order->billing_city . '",
        "address": "' . $order->billing_address_1 . " " . $order->billing_address_2 . '",
        "discount_code": "' . $coupons_list . '",
        "discount": ' . (empty($order->get_discount) ? 0 : $order->get_discount) . ',
        "shipping": ' . (empty($order->get_total_shipping) ? 0 : $order->get_total_shipping) . ',
        "total": ' . $order->order_total . '
    };
    _ra.saveOrderProducts =
        ' . json_encode($data['line_items'], JSON_PRETTY_PRINT) . '
    ;
    
    if( _ra.ready !== undefined ){
        _ra.saveOrder(_ra.saveOrderInfo, _ra.saveOrderProducts);
    }
</script>';
        }
        //endif
    }
Пример #23
0
                if (in_array($order->status, array('processing', 'completed')) && ($purchase_note = get_post_meta($_product->id, '_purchase_note', true))) {
                    ?>
									<td colspan="3"><?php 
                    echo apply_filters('the_content', $purchase_note);
                    ?>
</td>
								<?php 
                }
            }
        }
        ?>
					</tr>
				</tbody>
			</table>
			<?php 
        $coupons = $order->get_used_coupons();
        if (!empty($coupons)) {
            ?>
				<h2><?php 
            _e('Coupon Used :', $WCMp->text_domain);
            ?>
</h2>
				<table class="coupon_used"> 
					<tbody>
					  <tr>
							<?php 
            $coupon_used = false;
            foreach ($coupons as $coupon_code) {
                $coupon = new WC_Coupon($coupon_code);
                $coupon_post = get_post($coupon->id);
                $author_id = $coupon_post->post_author;
Пример #24
0
/**
 * Create coupons for a sub-order if neccessary
 *
 * @param WC_Order $parent_order
 * @param int $order_id
 * @param array $product_ids
 * @return type
 */
function dokan_create_sub_order_coupon($parent_order, $order_id, $product_ids)
{
    $used_coupons = $parent_order->get_used_coupons();
    if (!count($used_coupons)) {
        return;
    }
    if ($used_coupons) {
        foreach ($used_coupons as $coupon_code) {
            $coupon = new WC_Coupon($coupon_code);
            if ($coupon && !is_wp_error($coupon) && array_intersect($product_ids, $coupon->product_ids)) {
                // we found some match
                $item_id = wc_add_order_item($order_id, array('order_item_name' => $coupon_code, 'order_item_type' => 'coupon'));
                // Add line item meta
                if ($item_id) {
                    wc_add_order_item_meta($item_id, 'discount_amount', isset(WC()->cart->coupon_discount_amounts[$coupon_code]) ? WC()->cart->coupon_discount_amounts[$coupon_code] : 0);
                }
            }
        }
    }
}
Пример #25
0
 /**
  * Test: get_used_coupons
  */
 function test_get_used_coupons()
 {
     $object = new WC_Order();
     $item = new WC_Order_Item_Coupon();
     $item->set_props(array('code' => '12345', 'discount' => 10, 'discount_tax' => 5));
     $object->add_item($item);
     $object->save();
     $this->assertCount(1, $object->get_used_coupons());
 }
Пример #26
-1
function get_order_item_totals1( $tax_display = '' ) {
	if(is_wc_endpoint_url( 'order-received' ))
	{
		
		$order_id=wc_get_order_id_by_order_key( $_GET['key']);
		$order=new WC_Order($order_id);
		/*echo '<pre>';
		print_r($order);
		echo '</pre>';*/
		$coupons=$order->get_used_coupons();
		$coupon_code=$coupons[0];
		$coupon_data=new WC_Coupon($coupon_code);
		$discount = get_post_meta($coupon_data->id,'coupon_amount',true);
		$type = get_post_meta($coupon_data->id,'discount_type',true);
		
		if($type=='percent'){
			$coupon_label=$discount.'&#37; Rabatt';
		}
		else{
			$coupon_label='Rabatt';
		}
		if ( ! $tax_display ) {
			$tax_display = $order->tax_display_cart;
		}
		
		
		if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
			
			
			foreach ( $order->get_tax_totals() as $code => $tax ) {
				$tax->rate = WC_Tax::get_rate_percent( $tax->rate_id );
				
				if ( ! isset( $tax_array[ 'tax_rate'] ) )
					$tax_array[ 'tax_rate' ] = array( 'tax' => $tax, 'amount' => $tax->amount, 'contains' => array( $tax ) );
				else {
					array_push( $tax_array[ 'tax_rate' ][ 'contains' ], $tax );
					$tax_array[ 'tax_rate' ][ 'amount' ] += $tax->amount;
				}
			}
			if(isset($tax_array['tax_rate']['tax']->rate))
			$tax_label='<span class="include_tax">(inkl.&nbsp;'.$tax_array['tax_rate']['tax']->rate.'&nbsp;'.$tax_array['tax_rate']['tax']->label.')</span>';
		}
			
		$total_rows = array();
		
		$shippingcost='0 '.get_woocommerce_currency_symbol();
		
		if ( $order->get_total_discount() > 0 ) {
			$total_rows['discount'] = array(
				'label' => __( $coupon_label, 'woocommerce' ),
				'value'	=> '-' . $order->get_discount_to_display( $tax_display )
			);
		}

		
			$total_rows['shipping'] = array(
				'label' => __( 'Versandkosten', 'woocommerce' ),
				'value'	=>$shippingcost
			);
		

		$total_rows['order_total'] = array(
			'label' => __( 'Gesamtsumme '.$tax_label, 'woocommerce' ),
			'value'	=> $order->get_formatted_order_total( $tax_display )
		);

		return $total_rows;
	}
}