/**
  * create_custom_payment_gateways_fields_admin_order_meta_box.
  *
  * @version 2.5.2
  * @since   2.5.2
  */
 function create_custom_payment_gateways_fields_admin_order_meta_box()
 {
     $order_id = get_the_ID();
     $html = '';
     $input_fields = get_post_meta($order_id, '_wcj_custom_payment_gateway_input_fields', true);
     $table_data = array();
     foreach ($input_fields as $name => $value) {
         $table_data[] = array($name, $value);
     }
     $html .= wcj_get_table_html($table_data, array('table_class' => 'widefat striped', 'table_heading_type' => 'vertical'));
     echo $html;
 }
 /**
  * create_custom_tabs_meta_box.
  *
  * @version 2.5.0
  */
 public function create_custom_tabs_meta_box()
 {
     $current_post_id = get_the_ID();
     $option_name = 'wcj_custom_product_tabs_local_total_number';
     if (!($total_custom_tabs = get_post_meta($current_post_id, '_' . $option_name, true))) {
         $total_custom_tabs = apply_filters('booster_get_option', 1, get_option('wcj_custom_product_tabs_local_total_number_default', 1));
     }
     $html = '';
     $is_disabled = apply_filters('booster_get_message', '', 'readonly_string');
     $is_disabled_message = apply_filters('booster_get_message', '', 'desc');
     $html .= '<table>';
     $html .= '<tr>';
     $html .= '<th>';
     $html .= __('Total number of custom tabs', 'woocommerce-jetpack');
     $html .= '</th>';
     $html .= '<td>';
     $html .= '<input type="number" min="0" id="' . $option_name . '" name="' . $option_name . '" value="' . $total_custom_tabs . '" ' . $is_disabled . '>';
     $html .= '</td>';
     $html .= '<td>';
     $html .= __('Click "Update" product after you change this number.', 'woocommerce-jetpack') . '<br>' . $is_disabled_message;
     $html .= '</td>';
     $html .= '</td>';
     $html .= '</tr>';
     $html .= '</table>';
     echo $html;
     $options = array(array('id' => 'wcj_custom_product_tabs_title_local_', 'title' => __('Title', 'woocommerce-jetpack'), 'type' => 'text'), array('id' => 'wcj_custom_product_tabs_priority_local_', 'title' => __('Order', 'woocommerce-jetpack'), 'type' => 'number'), array('id' => 'wcj_custom_product_tabs_content_local_', 'title' => __('Content', 'woocommerce-jetpack'), 'type' => 'textarea'));
     $enable_wp_editor = get_option('wcj_custom_product_tabs_local_wp_editor_enabled', 'yes');
     $enable_wp_editor = 'yes' === $enable_wp_editor ? true : false;
     for ($i = 1; $i <= $total_custom_tabs; $i++) {
         $is_local_tab_visible = $this->is_local_tab_visible($i, $current_post_id);
         $readonly = $is_local_tab_visible ? '' : ' readonly';
         // not really used
         $disabled = $is_local_tab_visible ? '' : ' - ' . __('Disabled', 'woocommerce-jetpack');
         $data = array();
         $html = '<hr>';
         $html .= '<h4>' . __('Custom Product Tab', 'woocommerce-jetpack') . ' #' . $i . $disabled . '</h4>';
         if ($enable_wp_editor) {
             $the_field_wp_editor = array();
         }
         if ($is_local_tab_visible) {
             foreach ($options as $option) {
                 $option_id = $option['id'] . $i;
                 if (!($option_value = get_post_meta($current_post_id, '_' . $option_id, true))) {
                     $option_value = get_option($option['id'] . 'default_' . $i, '');
                     if ('' === $option_value && 'wcj_custom_product_tabs_priority_local_' === $option['id']) {
                         $option_value = 50;
                     }
                 }
                 switch ($option['type']) {
                     case 'number':
                         $the_field = '<input style="width:25%;min-width:100px;" type="' . $option['type'] . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '"' . $readonly . '>';
                         break;
                     case 'text':
                         $the_field = '<input style="width:50%;min-width:150px;" type="' . $option['type'] . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '"' . $readonly . '>';
                         break;
                     case 'textarea':
                         if ($enable_wp_editor) {
                             $the_field = '';
                             $the_field_wp_editor = array($option_id => $option_value);
                         } else {
                             $the_field = '<textarea style="width:100%;height:300px;" id="' . $option_id . '" name="' . $option_id . '"' . $readonly . '>' . $option_value . '</textarea>';
                         }
                         break;
                 }
                 if ('' != $the_field) {
                     $data[] = array($option['title'], $the_field);
                 }
             }
             $html .= wcj_get_table_html($data, array('table_class' => 'widefat', 'table_style' => 'margin-bottom:20px;', 'table_heading_type' => 'vertical', 'columns_styles' => array('width:10%;')));
         }
         echo $html;
         if ($enable_wp_editor && !empty($the_field_wp_editor)) {
             wp_editor(current($the_field_wp_editor), key($the_field_wp_editor));
         }
     }
     $html = '<input type="hidden" name="woojetpack_custom_tabs_save_post" value="woojetpack_custom_tabs_save_post">';
     echo $html;
 }
 function get_products_sales()
 {
     $products_data = array();
     $years = array();
     $total_orders = 0;
     $offset = 0;
     $block_size = 512;
     while (true) {
         $args_orders = array('post_type' => 'shop_order', 'post_status' => 'wc-completed', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset, 'date_query' => array(array('year' => $this->year)), 'fields' => 'ids');
         $loop_orders = new WP_Query($args_orders);
         if (!$loop_orders->have_posts()) {
             break;
         }
         foreach ($loop_orders->posts as $order_id) {
             $order = wc_get_order($order_id);
             $items = $order->get_items();
             foreach ($items as $item) {
                 $product_ids = array($item['product_id']);
                 if (0 != $item['variation_id'] && 'yes' === get_option('wcj_reports_products_sales_count_variations', 'no')) {
                     $product_ids[] = $item['variation_id'];
                 }
                 foreach ($product_ids as $product_id) {
                     // Total Sales
                     if (!isset($products_data[$product_id]['sales'])) {
                         $products_data[$product_id]['sales'] = 0;
                     }
                     $products_data[$product_id]['sales'] += $item['qty'];
                     // Total Sum
                     if (!isset($products_data[$product_id]['total_sum'])) {
                         $products_data[$product_id]['total_sum'] = 0;
                     }
                     $products_data[$product_id]['total_sum'] += $item['line_total'];
                     // Sales by Month
                     $month = date('n', get_the_time('U', $order_id));
                     $year = date('Y', get_the_time('U', $order_id));
                     $years[$year] = true;
                     if (!isset($products_data[$product_id]['sales_by_month'][$year][$month])) {
                         $products_data[$product_id]['sales_by_month'][$year][$month] = 0;
                     }
                     $products_data[$product_id]['sales_by_month'][$year][$month] += $item['qty'];
                     // Title
                     if (!isset($products_data[$product_id]['title'])) {
                         $products_data[$product_id]['title'] = '';
                         $_product = wc_get_product($product_id);
                         if (is_object($_product)) {
                             $products_data[$product_id]['title'] .= $_product->get_title();
                             // get_the_title( $product_id );
                             if ('WC_Product_Variation' === get_class($_product) && is_object($_product->parent)) {
                                 $products_data[$product_id]['title'] .= '<br><em>' . $_product->get_formatted_variation_attributes(true) . '</em>';
                             } elseif ('WC_Product_Variation' === get_class($_product)) {
                                 //									$products_data[ $product_id ][ 'title' ] .= ' [PARENT PRODUCT DELETED]'; // todo
                                 $products_data[$product_id]['title'] .= $item['name'] . '<br><em>' . __('Variation', 'woocommerce-jetpack') . '</em>';
                                 // get_the_title( $product_id );
                                 $products_data[$product_id]['title'] = '<del>' . $products_data[$product_id]['title'] . '</del>';
                             }
                         } else {
                             //								$products_data[ $product_id ][ 'title' ] .= $item['name'] . ' [PRODUCT DELETED]'; // todo
                             $products_data[$product_id]['title'] .= $item['name'];
                             $products_data[$product_id]['title'] = '<del>' . $products_data[$product_id]['title'] . '</del>';
                         }
                         //							$products_data[ $product_id ][ 'title' ] .= ' [ID: ' . $product_id . ']';
                     }
                     // Last Sale Time
                     if (!isset($products_data[$product_id]['last_sale'])) {
                         $products_data[$product_id]['last_sale'] = date('Y-m-d H:i:s', get_the_time('U', $order_id));
                     }
                     // Product ID
                     if (!isset($products_data[$product_id]['product_id'])) {
                         $products_data[$product_id]['product_id'] = $product_id;
                     }
                 }
             }
             $total_orders++;
         }
         $offset += $block_size;
     }
     //		usort( $products_data, array( $this, 'sort_by_total_sales' ) );
     usort($products_data, array($this, 'sort_by_title'));
     $table_data = array();
     $the_header = array(__('ID', 'woocommerce-jetpack'), __('Product', 'woocommerce-jetpack'), __('Last Sale', 'woocommerce-jetpack'), __('Total Sales', 'woocommerce-jetpack'), __('Total Sum', 'woocommerce-jetpack'));
     foreach ($years as $year => $value) {
         if ($year != $this->year) {
             continue;
         }
         for ($i = 12; $i >= 1; $i--) {
             $the_header[] = sprintf('%04d.%02d', $year, $i);
         }
     }
     $table_data[] = $the_header;
     foreach ($products_data as $the_data) {
         if ('' == $this->product_title || false !== stripos($the_data['title'], $this->product_title)) {
             $the_row = array($the_data['product_id'], $the_data['title'], $the_data['last_sale'], $the_data['sales'], wc_price($the_data['total_sum']));
             foreach ($years as $year => $value) {
                 if ($year != $this->year) {
                     continue;
                 }
                 for ($i = 12; $i >= 1; $i--) {
                     if (isset($the_data['sales_by_month'][$year][$i])) {
                         if ($i > 1) {
                             $prev_month_data = isset($the_data['sales_by_month'][$year][$i - 1]) ? $the_data['sales_by_month'][$year][$i - 1] : 0;
                             $color = $prev_month_data >= $the_data['sales_by_month'][$year][$i] ? 'red' : 'green';
                         } else {
                             $color = 'black';
                         }
                         $the_row[] = '<span style="color:' . $color . ';">' . $the_data['sales_by_month'][$year][$i] . '</span>';
                     } else {
                         $the_row[] = '';
                     }
                 }
             }
             $table_data[] = $the_row;
         }
     }
     $menu = '';
     $menu .= '<ul class="subsubsub">';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y')) . '" class="' . ($this->year == date('Y') ? 'current' : '') . '">' . date('Y') . '</a> | </li>';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y') - 1) . '" class="' . ($this->year == date('Y') - 1 ? 'current' : '') . '">' . (date('Y') - 1) . '</a> | </li>';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y') - 2) . '" class="' . ($this->year == date('Y') - 2 ? 'current' : '') . '">' . (date('Y') - 2) . '</a></li>';
     $menu .= '</ul>';
     $menu .= '<br class="clear">';
     $filter_form = '';
     $filter_form .= '<form method="get" action="">';
     $filter_form .= '<input type="hidden" name="page" value="' . $_GET['page'] . '" />';
     $filter_form .= '<input type="hidden" name="tab" value="' . $_GET['tab'] . '" />';
     $filter_form .= '<input type="hidden" name="report" value="' . $_GET['report'] . '" />';
     $filter_form .= '<input type="text" name="product_title" title="" value="' . $this->product_title . '" /><input type="submit" value="' . __('Filter products', 'woocommerce-jetpack') . '" />';
     $filter_form .= '</form>';
     $the_results = !empty($products_data) ? wcj_get_table_html($table_data, array('table_class' => 'widefat striped')) : '<p><em>' . __('No sales data for current period.') . '</em></p>';
     return '<p>' . $menu . '</p>' . '<p>' . $filter_form . '</p>' . $the_results;
 }
 /**
  * wcj_product_add_new.
  *
  * @version 2.5.4
  * @since   2.5.0
  */
 function wcj_product_add_new($atts)
 {
     $header_html = '';
     $notice_html = '';
     $input_fields_html = '';
     $footer_html = '';
     $args = array('title' => isset($_REQUEST['wcj_add_new_product_title']) ? $_REQUEST['wcj_add_new_product_title'] : '', 'desc' => isset($_REQUEST['wcj_add_new_product_desc']) ? $_REQUEST['wcj_add_new_product_desc'] : '', 'short_desc' => isset($_REQUEST['wcj_add_new_product_short_desc']) ? $_REQUEST['wcj_add_new_product_short_desc'] : '', 'regular_price' => isset($_REQUEST['wcj_add_new_product_regular_price']) ? $_REQUEST['wcj_add_new_product_regular_price'] : '', 'sale_price' => isset($_REQUEST['wcj_add_new_product_sale_price']) ? $_REQUEST['wcj_add_new_product_sale_price'] : '', 'cats' => isset($_REQUEST['wcj_add_new_product_cats']) ? $_REQUEST['wcj_add_new_product_cats'] : array(), 'tags' => isset($_REQUEST['wcj_add_new_product_tags']) ? $_REQUEST['wcj_add_new_product_tags'] : array(), 'image' => isset($_FILES['wcj_add_new_product_image']) ? $_FILES['wcj_add_new_product_image'] : '');
     if (isset($_REQUEST['wcj_add_new_product'])) {
         if (true === ($validate_args = $this->validate_args($args, $atts))) {
             $result = $this->wc_add_new_product($args, $atts);
             if (0 == $result) {
                 // Error
                 $notice_html .= '<div class="woocommerce"><ul class="woocommerce-error"><li>' . __('Error!', 'woocommerce-jetpack') . '</li></ul></div>';
             } else {
                 // Success
                 if (0 == $atts['product_id']) {
                     $notice_html .= '<div class="woocommerce"><div class="woocommerce-message">' . str_replace('%product_title%', $args['title'], get_option('wcj_product_by_user_message_product_successfully_added', __('"%product_title%" successfully added!', 'woocommerce-jetpack'))) . '</div></div>';
                 } else {
                     $notice_html .= '<div class="woocommerce"><div class="woocommerce-message">' . str_replace('%product_title%', $args['title'], get_option('wcj_product_by_user_message_product_successfully_edited', __('"%product_title%" successfully edited!', 'woocommerce-jetpack'))) . '</div></div>';
                 }
                 //					$atts['product_id'] = $result;
             }
         } else {
             $notice_html .= '<div class="woocommerce"><ul class="woocommerce-error">' . $validate_args . '</ul></div>';
         }
     }
     if (isset($_GET['wcj_edit_product_image_delete'])) {
         $product_id = $_GET['wcj_edit_product_image_delete'];
         $post_author_id = get_post_field('post_author', $product_id);
         $user_ID = get_current_user_id();
         if ($user_ID != $post_author_id) {
             echo '<p>' . __('Wrong user ID!', 'woocommerce-jetpack') . '</p>';
         } else {
             $image_id = get_post_thumbnail_id($product_id);
             wp_delete_post($image_id, true);
         }
     }
     if (0 != $atts['product_id']) {
         $this->the_product = wc_get_product($atts['product_id']);
     }
     $header_html .= '<h3>';
     $header_html .= 0 == $atts['product_id'] ? __('Add New Product', 'woocommerce-jetpack') : __('Edit Product', 'woocommerce-jetpack');
     $header_html .= '</h3>';
     $header_html .= '<form method="post" action="' . remove_query_arg(array('wcj_edit_product_image_delete', 'wcj_delete_product')) . '" enctype="multipart/form-data">';
     // todo multipart only if image...
     $required_mark_html_template = '&nbsp;<abbr class="required" title="required">*</abbr>';
     $table_data = array();
     $input_style = 'width:100%;';
     $table_data[] = array('<label for="wcj_add_new_product_title">' . __('Title', 'woocommerce-jetpack') . $required_mark_html_template . '</label>', '<input required type="text" style="' . $input_style . '" id="wcj_add_new_product_title" name="wcj_add_new_product_title" value="' . (0 != $atts['product_id'] ? $this->the_product->get_title() : $args['title']) . '">');
     if ('yes' === $atts['desc_enabled']) {
         $required_html = 'yes' === $atts['desc_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['desc_required'] ? $required_mark_html_template : '';
         $table_data[] = array('<label for="wcj_add_new_product_desc">' . __('Description', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<textarea' . $required_html . ' style="' . $input_style . '" id="wcj_add_new_product_desc" name="wcj_add_new_product_desc">' . (0 != $atts['product_id'] ? get_post_field('post_content', $atts['product_id']) : $args['desc']) . '</textarea>');
     }
     if ('yes' === $atts['short_desc_enabled']) {
         $required_html = 'yes' === $atts['short_desc_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['short_desc_required'] ? $required_mark_html_template : '';
         $table_data[] = array('<label for="wcj_add_new_product_short_desc">' . __('Short Description', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<textarea' . $required_html . ' style="' . $input_style . '" id="wcj_add_new_product_short_desc" name="wcj_add_new_product_short_desc">' . (0 != $atts['product_id'] ? get_post_field('post_excerpt', $atts['product_id']) : $args['short_desc']) . '</textarea>');
     }
     if ('yes' === $atts['image_enabled']) {
         $required_html = 'yes' === $atts['image_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['image_required'] ? $required_mark_html_template : '';
         $new_image_field = '<input' . $required_html . ' type="file" id="wcj_add_new_product_image" name="wcj_add_new_product_image" accept="image/*">';
         if (0 != $atts['product_id']) {
             $the_field = '' == get_post_thumbnail_id($atts['product_id']) ? $new_image_field : '<a href="' . add_query_arg('wcj_edit_product_image_delete', $atts['product_id']) . '" onclick="return confirm(\'' . __('Are you sure?', 'woocommerce-jetpack') . '\')">' . __('Delete', 'woocommerce-jetpack') . '</a><br>' . get_the_post_thumbnail($atts['product_id'], array(50, 50), array('class' => 'alignleft'));
         } else {
             $the_field = $new_image_field;
         }
         $table_data[] = array('<label for="wcj_add_new_product_image">' . __('Image', 'woocommerce-jetpack') . $required_mark_html . '</label>', $the_field);
     }
     if ('yes' === $atts['regular_price_enabled']) {
         $required_html = 'yes' === $atts['regular_price_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['regular_price_required'] ? $required_mark_html_template : '';
         $table_data[] = array('<label for="wcj_add_new_product_regular_price">' . __('Regular Price', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<input' . $required_html . ' type="number" min="0" step="0.01" id="wcj_add_new_product_regular_price" name="wcj_add_new_product_regular_price" value="' . (0 != $atts['product_id'] ? get_post_meta($atts['product_id'], '_regular_price', true) : $args['regular_price']) . '">');
     }
     if ('yes' === $atts['sale_price_enabled']) {
         $required_html = 'yes' === $atts['sale_price_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['sale_price_required'] ? $required_mark_html_template : '';
         $table_data[] = array('<label for="wcj_add_new_product_sale_price">' . __('Sale Price', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<input' . $required_html . ' type="number" min="0" step="0.01" id="wcj_add_new_product_sale_price" name="wcj_add_new_product_sale_price" value="' . (0 != $atts['product_id'] ? get_post_meta($atts['product_id'], '_sale_price', true) : $args['sale_price']) . '">');
     }
     if ('yes' === $atts['cats_enabled']) {
         $required_html = 'yes' === $atts['cats_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['cats_required'] ? $required_mark_html_template : '';
         $current_product_categories = 0 != $atts['product_id'] ? get_the_terms($atts['product_id'], 'product_cat') : $args['cats'];
         $product_categories = get_terms('product_cat', 'orderby=name&hide_empty=0');
         $product_categories_as_select_options = '';
         foreach ($product_categories as $product_category) {
             $selected = '';
             if (!empty($current_product_categories)) {
                 foreach ($current_product_categories as $current_product_category) {
                     if (is_object($current_product_category)) {
                         $current_product_category = $current_product_category->slug;
                     }
                     $selected .= selected($current_product_category, $product_category->slug, false);
                 }
             }
             $product_categories_as_select_options .= '<option value="' . $product_category->slug . '" ' . $selected . '>' . $product_category->name . '</option>';
         }
         $table_data[] = array('<label for="wcj_add_new_product_cats">' . __('Categories', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<select' . $required_html . ' multiple style="' . $input_style . '" id="wcj_add_new_product_cats" name="wcj_add_new_product_cats[]">' . $product_categories_as_select_options . '</select>');
     }
     if ('yes' === $atts['tags_enabled']) {
         $required_html = 'yes' === $atts['tags_required'] ? ' required' : '';
         $required_mark_html = 'yes' === $atts['tags_required'] ? $required_mark_html_template : '';
         $current_product_tags = 0 != $atts['product_id'] ? get_the_terms($atts['product_id'], 'product_tag') : $args['tags'];
         $products_tags = get_terms('product_tag', 'orderby=name&hide_empty=0');
         $products_tags_as_select_options = '';
         foreach ($products_tags as $products_tag) {
             $selected = '';
             if (!empty($current_product_tags)) {
                 foreach ($current_product_tags as $current_product_tag) {
                     if (is_object($current_product_tag)) {
                         $current_product_tag = $current_product_tag->slug;
                     }
                     $selected .= selected($current_product_tag, $products_tag->slug, false);
                 }
             }
             $products_tags_as_select_options .= '<option value="' . $products_tag->slug . '" ' . $selected . '>' . $products_tag->name . '</option>';
         }
         $table_data[] = array('<label for="wcj_add_new_product_tags">' . __('Tags', 'woocommerce-jetpack') . $required_mark_html . '</label>', '<select' . $required_html . ' multiple style="' . $input_style . '" id="wcj_add_new_product_tags" name="wcj_add_new_product_tags[]">' . $products_tags_as_select_options . '</select>');
     }
     $input_fields_html .= wcj_get_table_html($table_data, array('table_class' => 'widefat', 'table_heading_type' => 'vertical'));
     $footer_html .= '<input type="submit" class="button" name="wcj_add_new_product" value="' . (0 == $atts['product_id'] ? __('Add', 'woocommerce-jetpack') : __('Edit', 'woocommerce-jetpack')) . '">';
     $footer_html .= '</form>';
     return $notice_html . $header_html . $input_fields_html . $footer_html;
 }
 function get_products_atts()
 {
     $total_products = 0;
     $products_attributes = array();
     $attributes_names = array();
     $attributes_names['wcj_title'] = __('Product', 'woocommerce-jetpack');
     $attributes_names['wcj_category'] = __('Category', 'woocommerce-jetpack');
     $offset = 0;
     $block_size = 96;
     while (true) {
         $args_products = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $block_size, 'orderby' => 'title', 'order' => 'ASC', 'offset' => $offset);
         $loop_products = new WP_Query($args_products);
         if (!$loop_products->have_posts()) {
             break;
         }
         while ($loop_products->have_posts()) {
             $loop_products->the_post();
             $total_products++;
             $product_id = $loop_products->post->ID;
             $the_product = wc_get_product($product_id);
             $products_attributes[$product_id]['wcj_title'] = '<a href="' . get_permalink($product_id) . '">' . $the_product->get_title() . '</a>';
             $products_attributes[$product_id]['wcj_category'] = $the_product->get_categories();
             foreach ($the_product->get_attributes() as $attribute) {
                 $products_attributes[$product_id][$attribute['name']] = $the_product->get_attribute($attribute['name']);
                 if (!isset($attributes_names[$attribute['name']])) {
                     $attributes_names[$attribute['name']] = wc_attribute_label($attribute['name']);
                 }
             }
         }
         $offset += $block_size;
     }
     $table_data = array();
     if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
         $table_data[] = array(__('Product', 'woocommerce-jetpack'), __('Category', 'woocommerce-jetpack'), $_GET['wcj_attribute']);
     } else {
         //			$table_data[] = array_values( $attributes_names );
         $table_data[] = array_keys($attributes_names);
     }
     foreach ($attributes_names as $attributes_name => $attribute_title) {
         if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
             if ('wcj_title' != $attributes_name && 'wcj_category' != $attributes_name && $_GET['wcj_attribute'] != $attributes_name) {
                 continue;
             }
         }
         foreach ($products_attributes as $product_id => $product_attributes) {
             $table_data[$product_id][$attributes_name] = isset($product_attributes[$attributes_name]) ? $product_attributes[$attributes_name] : '';
         }
     }
     return '<p>' . __('Total Products:', 'woocommerce-jetpack') . ' ' . $total_products . '</p>' . wcj_get_table_html($table_data, array('table_class' => 'widefat striped'));
 }
 /**
  * create_bulk_price_converter_tool.
  *
  * @version 2.4.0
  */
 public function create_bulk_price_converter_tool()
 {
     $result_message = '';
     $multiply_prices_by = isset($_POST['multiply_prices_by']) ? $_POST['multiply_prices_by'] : 1;
     $is_preview = isset($_POST['bulk_change_prices_preview']) ? true : false;
     $result_changing_prices = '';
     if ($multiply_prices_by <= 0) {
         $result_message = '<p><div class="error"><p><strong>' . __('Multiply value must be above zero.', 'woocommerce-jetpack') . '</strong></p></div></p>';
         $multiply_prices_by = 1;
     } else {
         if (isset($_POST['bulk_change_prices']) || isset($_POST['bulk_change_prices_preview'])) {
             $result_changing_prices = $this->change_all_products_prices($multiply_prices_by, $is_preview);
             if (!$is_preview) {
                 $result_message = '<p><div class="updated"><p><strong>' . __('Prices changed successfully!', 'woocommerce-jetpack') . '</strong></p></div></p>';
                 $multiply_prices_by = 1;
             }
         }
     }
     $select_options_html = '';
     $selected_option = isset($_POST['wcj_product_cat']) ? $_POST['wcj_product_cat'] : '';
     $product_categories = get_terms('product_cat', 'orderby=name&hide_empty=0');
     if (!empty($product_categories) && !is_wp_error($product_categories)) {
         foreach ($product_categories as $product_category) {
             $select_options_html .= '<option value="' . $product_category->slug . '"' . selected($product_category->slug, $selected_option, false) . '>' . $product_category->name . '</option>';
         }
     }
     // Output HTML
     echo '<div>';
     echo $this->get_tool_header_html('bulk_price_converter');
     echo $result_message;
     echo '<form method="post" action="">';
     $data_table = array();
     $data_table[] = array(__('Multiply all product prices by', 'woocommerce-jetpack'), '<input class="" type="number" step="0.000001" min="0.000001" name="multiply_prices_by" id="multiply_prices_by" value="' . $multiply_prices_by . '">');
     if ('' != $select_options_html) {
         $data_table[] = array(__('Category', 'woocommerce-jetpack'), '<select name="wcj_product_cat" ' . apply_filters('wcj_get_option_filter', 'disabled', '') . '>' . '<option value="wcj_any">' . __('Any', 'woocommerce-jetpack') . '</option>' . $select_options_html . '</select>' . ' ' . apply_filters('get_wc_jetpack_plus_message', '', 'desc'));
     }
     $data_table[] = array('<input class="button-primary" type="submit" name="bulk_change_prices_preview" id="bulk_change_prices_preview" value="' . __('Preview Prices', 'woocommerce-jetpack') . '">', '');
     if (isset($_POST['bulk_change_prices_preview'])) {
         $data_table[] = array('<input class="button-primary" type="submit" name="bulk_change_prices" id="bulk_change_prices" value="' . __('Change Prices', 'woocommerce-jetpack') . '">', '');
     }
     /* <input type="checkbox" name="make_pretty_prices" id="make_pretty_prices" value="">Make Pretty Prices */
     echo wcj_get_table_html($data_table, array('table_heading_type' => 'none'));
     echo '</form>';
     if ($is_preview) {
         echo $result_changing_prices;
     }
     echo '</div>';
 }
 /**
  * Invoices Report function.
  */
 function get_invoices_report($year, $month)
 {
     $output = '';
     $data = array();
     $data[] = array(__('Invoice Nr.', 'woocommerce-jetpack'), __('Invoice Date', 'woocommerce-jetpack'), __('Order ID', 'woocommerce-jetpack'), __('Customer Country', 'woocommerce-jetpack'), __('Tax %', 'woocommerce-jetpack'), __('Order Total Tax Excl.', 'woocommerce-jetpack'), __('Order Taxes', 'woocommerce-jetpack'), __('Order Total', 'woocommerce-jetpack'), __('Order Currency', 'woocommerce-jetpack'));
     $total_sum = 0;
     $total_sum_excl_tax = 0;
     $total_tax = 0;
     $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC', 'year' => $year, 'monthnum' => $month);
     $loop = new WP_Query($args);
     while ($loop->have_posts()) {
         $loop->the_post();
         $order_id = $loop->post->ID;
         $invoice_type_id = 'invoice';
         if (wcj_is_invoice_created($order_id, $invoice_type_id)) {
             $the_order = wc_get_order($order_id);
             $user_meta = get_user_meta($the_order->get_user_id());
             $billing_country = isset($user_meta['billing_country'][0]) ? $user_meta['billing_country'][0] : '';
             $shipping_country = isset($user_meta['shipping_country'][0]) ? $user_meta['shipping_country'][0] : '';
             $customer_country = '' == $billing_country ? $shipping_country : $billing_country;
             $order_total = $the_order->get_total();
             $order_tax = apply_filters('wcj_order_total_tax', $the_order->get_total_tax(), $the_order);
             //$order_tax_percent = ( isset( $taxes_by_countries_eu[ $customer_country ] ) ) ? $taxes_by_countries_eu[ $customer_country ] : 0;
             //$order_tax_percent /= 100;
             //$order_tax = $order_total * $order_tax_percent;
             $order_total_exlc_tax = $order_total - $order_tax;
             $order_tax_percent = 0 == $order_total ? 0 : $order_tax / $order_total_exlc_tax;
             $total_sum += $order_total;
             $total_sum_excl_tax += $order_total_exlc_tax;
             $total_tax += $order_tax;
             //$order_tax_html = ( 0 == $order_tax ) ? '' : sprintf( '$ %.2f', $order_tax );
             $order_tax_html = sprintf('%.2f', $order_tax);
             $data[] = array(wcj_get_invoice_number($order_id, $invoice_type_id), wcj_get_invoice_date($order_id, $invoice_type_id, 0, get_option('date_format')), $order_id, $customer_country, sprintf('%.0f %%', $order_tax_percent * 100), sprintf('%.2f', $order_total_exlc_tax), $order_tax_html, sprintf('%.2f', $order_total), $the_order->get_order_currency());
         }
     }
     /* $output .= '<h3>' . 'Total Sum Excl. Tax: ' . sprintf( '$ %.2f', $total_sum_excl_tax ) . '</h3>';
     		$output .= '<h3>' . 'Total Sum: ' . sprintf( '$ %.2f', $total_sum ) . '</h3>';
     		$output .= '<h3>' . 'Total Tax: ' . sprintf( '$ %.2f', $total_tax ) . '</h3>'; */
     $output .= wcj_get_table_html($data, array('table_class' => 'widefat'));
     /**/
     return $output;
 }
 /**
  * wcj_product_wholesale_price_table.
  */
 function wcj_product_wholesale_price_table($atts)
 {
     if (!wcj_is_product_wholesale_enabled($this->the_product->id)) {
         return '';
     }
     $wholesale_price_levels = array();
     for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_wholesale_price_levels_number', 1)); $i++) {
         $level_qty = get_option('wcj_wholesale_price_level_min_qty_' . $i, PHP_INT_MAX);
         $discount_percent = get_option('wcj_wholesale_price_level_discount_percent_' . $i, 0);
         $discount_koef = 1.0 - $discount_percent / 100.0;
         $wholesale_price_levels[] = array('quantity' => $level_qty, 'koef' => $discount_koef, 'discount_percent' => $discount_percent);
     }
     $data_qty = array();
     $data_price = array();
     foreach ($wholesale_price_levels as $wholesale_price_level) {
         $the_price = '';
         // Variable
         if ($this->the_product->is_type('variable')) {
             $min = $this->the_product->get_variation_price('min', false);
             $max = $this->the_product->get_variation_price('max', false);
             if ('' !== $wholesale_price_level['koef'] && is_numeric($wholesale_price_level['koef'])) {
                 $min = $min * $wholesale_price_level['koef'];
                 $max = $max * $wholesale_price_level['koef'];
             }
             if ('yes' !== $atts['hide_currency']) {
                 $min = wc_price($min);
                 $max = wc_price($max);
             }
             $the_price = sprintf('%s-%s', $min, $max);
         } else {
             //$the_price = wc_price( round( $this->the_product->get_price() * $wholesale_price_level['koef'], $precision ) );
             $the_price = $this->the_product->get_price();
             if ('' !== $wholesale_price_level['koef'] && is_numeric($wholesale_price_level['koef'])) {
                 $the_price = $the_price * $wholesale_price_level['koef'];
             }
             if ('yes' !== $atts['hide_currency']) {
                 $the_price = wc_price($the_price);
             }
         }
         $data_qty[] = str_replace('%level_qty%', $wholesale_price_level['quantity'], $atts['heading_format']);
         $data_price[] = $the_price;
         if ('yes' === $atts['add_percent_row']) {
             $data_discount_percent[] = '-' . $wholesale_price_level['discount_percent'] . '%';
         }
     }
     $table_rows = array($data_qty, $data_price);
     if ('yes' === $atts['add_percent_row']) {
         $table_rows[] = $data_discount_percent;
     }
     $table_styles = array('columns_styles' => array('text-align: center;', 'text-align: center;', 'text-align: center;'));
     return wcj_get_table_html($table_rows, $table_styles);
 }
 /**
  * get_data function.
  */
 public function get_html($data, $total_customers, $report_type = 'all_countries')
 {
     $html = '';
     if ('all_countries' === $report_type) {
         $html .= '<h5>' . __('Total customers', 'woocommerce-jetpack') . ': ' . $total_customers . '</h5>';
         $html .= '<table class="widefat" style="width:100% !important;"><tbody>';
         $html .= '<tr>';
         $html .= '<th></th>';
         //'<th>' . __( 'Country Flag', 'woocommerce-jetpack' ) . '</th>';
         $html .= '<th>' . __('Country Code', 'woocommerce-jetpack') . '</th>';
         $html .= '<th>' . __('Customers Count', 'woocommerce-jetpack') . '</th>';
         $html .= '<th>' . __('Percent of total', 'woocommerce-jetpack') . '</th>';
         $html .= '<th></th>';
         $html .= '<th></th>';
         $html .= '</tr>';
         $i = 0;
         foreach ($data as $country_code => $result) {
             $result = $result['customer_counter'];
             $html .= '<tr>';
             $html .= '<td>' . ++$i . '</td>';
             $country_code_link = '<a href="' . add_query_arg(array('country' => $country_code)) . '">' . $country_code . '</a>';
             $html .= 2 == strlen($country_code) ? '<td>' . $country_code_link . '</td>' : '<td>' . $country_code . '</td>';
             $html .= '<td>' . $result . '</td>';
             $html .= 0 != $total_customers ? '<td>' . number_format($result / $total_customers * 100, 2) . '%' . '</td>' : '<td></td>';
             $country_flag_img = '<img src="' . plugins_url() . '/' . 'woocommerce-jetpack' . '/assets/images/flag-icons/' . strtolower($country_code) . '.png" title="' . wcj_get_country_name_by_code($country_code) . '">';
             $country_flag_img_link = '<a href="' . add_query_arg(array('country' => $country_code)) . '">' . $country_flag_img . ' ' . wcj_get_country_name_by_code($country_code) . '</a>';
             $html .= 2 == strlen($country_code) ? '<td>' . $country_flag_img_link . '</td>' : '<td></td>';
             $html .= '</tr>';
         }
         $html .= '</tbody></table>';
     } else {
         //if ( 'single_country' === $report_type ) {
         $country_code = $report_type;
         $html .= '<h5>' . __('Report for:', 'woocommerce-jetpack') . ' ' . wcj_get_country_name_by_code($country_code) . ' [' . $country_code . ']' . '</h5>';
         $html .= 2 == strlen($country_code) ? wcj_get_table_html($data[$country_code]['total_spent'], array('table_class' => 'widefat')) : '';
     }
     return $html;
 }
 /**
  * get_settings.
  *
  * @version 2.5.8
  */
 function get_settings()
 {
     $settings = array(array('title' => __('Admin Tools Options', 'woocommerce-jetpack'), 'type' => 'title', 'id' => 'wcj_admin_tools_module_options'), array('title' => __('Logging', 'woocommerce-jetpack'), 'desc' => __('Enable', 'woocommerce-jetpack'), 'id' => 'wcj_logging_enabled', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('Debug', 'woocommerce-jetpack'), 'desc' => __('Enable', 'woocommerce-jetpack'), 'id' => 'wcj_debuging_enabled', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('PHP Memory Limit', 'woocommerce-jetpack'), 'desc' => __('megabytes.', 'woocommerce-jetpack'), 'desc_tip' => __('Set zero to disable.', 'woocommerce-jetpack') . $this->current_php_memory_limit, 'id' => 'wcj_admin_tools_php_memory_limit', 'default' => 0, 'type' => 'number', 'custom_attributes' => array('min' => 0)), array('title' => __('System Info', 'woocommerce-jetpack'), 'id' => 'wcj_admin_tools_system_info', 'default' => '', 'type' => 'custom_link', 'link' => '<pre>' . wcj_get_table_html($this->get_system_info_table_array(), array('columns_styles' => array('padding:0;', 'padding:0;'), 'table_heading_type' => 'vertical')) . '</pre>'), array('title' => __('Show Order Meta', 'woocommerce-jetpack'), 'desc' => __('Enable', 'woocommerce-jetpack'), 'id' => 'wcj_admin_tools_show_order_meta_enabled', 'default' => 'no', 'type' => 'checkbox'), array('title' => __('Show Product Meta', 'woocommerce-jetpack'), 'desc' => __('Enable', 'woocommerce-jetpack'), 'id' => 'wcj_admin_tools_show_product_meta_enabled', 'default' => 'no', 'type' => 'checkbox'), array('type' => 'sectionend', 'id' => 'wcj_admin_tools_module_options'));
     return $this->add_standard_settings($settings);
 }
 /**
  * wcj_wholesale_price_table (global only).
  *
  * @version 2.5.7
  * @since   2.4.8
  */
 function wcj_wholesale_price_table($atts)
 {
     if (!wcj_is_module_enabled('wholesale_price')) {
         return '';
     }
     // Check for user role options
     $role_option_name_addon = '';
     $user_roles = get_option('wcj_wholesale_price_by_user_role_roles', '');
     if (!empty($user_roles)) {
         $current_user_role = wcj_get_current_user_first_role();
         foreach ($user_roles as $user_role_key) {
             if ($current_user_role === $user_role_key) {
                 $role_option_name_addon = '_' . $user_role_key;
                 break;
             }
         }
     }
     $wholesale_price_levels = array();
     for ($i = 1; $i <= apply_filters('booster_get_option', 1, get_option('wcj_wholesale_price_levels_number' . $role_option_name_addon, 1)); $i++) {
         $level_qty = get_option('wcj_wholesale_price_level_min_qty' . $role_option_name_addon . '_' . $i, PHP_INT_MAX);
         $discount = get_option('wcj_wholesale_price_level_discount_percent' . $role_option_name_addon . '_' . $i, 0);
         $wholesale_price_levels[] = array('quantity' => $level_qty, 'discount' => $discount);
     }
     $data_qty = array();
     $data_discount = array();
     $columns_styles = array();
     $i = -1;
     foreach ($wholesale_price_levels as $wholesale_price_level) {
         $i++;
         if (0 == $wholesale_price_level['quantity'] && 'yes' === $atts['hide_if_zero_quantity']) {
             continue;
         }
         $level_max_qty = isset($wholesale_price_levels[$i + 1]['quantity']) ? $atts['before_level_max_qty'] . ($wholesale_price_levels[$i + 1]['quantity'] - 1) : $atts['last_level_max_qty'];
         $data_qty[] = str_replace(array('%level_qty%', '%level_min_qty%', '%level_max_qty%'), array($wholesale_price_level['quantity'], $wholesale_price_level['quantity'], $level_max_qty), $atts['heading_format']);
         $data_discount[] = 'fixed' === get_option('wcj_wholesale_price_discount_type', 'percent') ? '-' . wc_price($wholesale_price_level['discount']) : '-' . $wholesale_price_level['discount'] . '%';
         $columns_styles[] = 'text-align: center;';
     }
     $table_rows = array($data_qty, $data_discount);
     if ('vertical' === $atts['table_format']) {
         $table_rows_modified = array();
         foreach ($table_rows as $row_number => $table_row) {
             foreach ($table_row as $column_number => $cell) {
                 $table_rows_modified[$column_number][$row_number] = $cell;
             }
         }
         $table_rows = $table_rows_modified;
     }
     return wcj_get_table_html($table_rows, array('table_class' => 'wcj_wholesale_price_table', 'columns_styles' => $columns_styles, 'table_heading_type' => $atts['table_format']));
 }
 /**
  * Invoices Report function.
  *
  * @version 2.5.7
  */
 function get_invoices_report($year, $month, $invoice_type_id)
 {
     $output = '';
     $data = $this->get_invoices_report_data($year, $month, $invoice_type_id);
     $output .= wcj_get_table_html($data, array('table_class' => 'widefat'));
     return $output;
 }
 /**
  * add_input_fields_to_frontend.
  *
  * @version 2.5.2
  * @since   2.5.0
  */
 function add_input_fields_to_frontend()
 {
     if ($this->is_bookings_product(wc_get_product())) {
         $data_table = array();
         $date_from_value = isset($_POST['wcj_product_bookings_date_from']) ? $_POST['wcj_product_bookings_date_from'] : '';
         $date_to_value = isset($_POST['wcj_product_bookings_date_to']) ? $_POST['wcj_product_bookings_date_to'] : '';
         $data_table[] = array('<label for="wcj_product_bookings_date_to">' . get_option('wcj_product_bookings_label_date_from', __('Date from')) . '</label>', '<input firstday="0" dateformat="mm/dd/yy" mindate="0" type="datepicker" display="date" id="wcj_product_bookings_date_from" name="wcj_product_bookings_date_from" placeholder="" value="' . $date_from_value . '">');
         $data_table[] = array('<label for="wcj_product_bookings_date_to">' . get_option('wcj_product_bookings_label_date_to', __('Date to')) . '</label>', '<input firstday="0" dateformat="mm/dd/yy" mindate="0" type="datepicker" display="date" id="wcj_product_bookings_date_to" name="wcj_product_bookings_date_to" placeholder="" value="' . $date_to_value . '">');
         echo wcj_get_table_html($data_table, array('table_heading_type' => 'none'));
         echo '<div style="display:none !important;" name="wcj_bookings_message"><p style="color:red;"></p></div>';
     }
 }
 function get_products_sales()
 {
     $products_data = array();
     $years = array();
     $total_orders = 0;
     $offset = 0;
     $block_size = 96;
     while (true) {
         $args_orders = array('post_type' => 'shop_order', 'post_status' => 'wc-completed', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset, 'date_query' => array(array('year' => $this->year)));
         $loop_orders = new WP_Query($args_orders);
         if (!$loop_orders->have_posts()) {
             break;
         }
         while ($loop_orders->have_posts()) {
             $loop_orders->the_post();
             $order_id = $loop_orders->post->ID;
             $order = new WC_Order($order_id);
             $items = $order->get_items();
             foreach ($items as $item) {
                 if (!isset($products_data[$item['product_id']]['sales'])) {
                     $products_data[$item['product_id']]['sales'] = 0;
                 }
                 $products_data[$item['product_id']]['sales'] += $item['qty'];
                 $month = date('n', get_the_time('U'));
                 $year = date('Y', get_the_time('U'));
                 $years[$year] = true;
                 if (!isset($products_data[$item['product_id']]['sales_by_month'][$year][$month])) {
                     $products_data[$item['product_id']]['sales_by_month'][$year][$month] = 0;
                 }
                 $products_data[$item['product_id']]['sales_by_month'][$year][$month] += $item['qty'];
                 if (!isset($products_data[$item['product_id']]['title'])) {
                     $products_data[$item['product_id']]['title'] = get_the_title($item['product_id']);
                 }
                 if (!isset($products_data[$item['product_id']]['last_sale'])) {
                     $products_data[$item['product_id']]['last_sale'] = date('Y-m-d H:i:s', get_the_time('U'));
                 }
             }
             $total_orders++;
         }
         $offset += $block_size;
     }
     usort($products_data, array($this, 'sort_by_total_sales'));
     $table_data = array();
     $the_header = array(__('Product', 'woocommerce-jetpack'));
     foreach ($years as $year => $value) {
         if ($year != $this->year) {
             continue;
         }
         for ($i = 12; $i >= 1; $i--) {
             $the_header[] = sprintf('%04d.%02d', $year, $i);
         }
     }
     $table_data[] = $the_header;
     foreach ($products_data as $product_id => $the_data) {
         $the_row = array($the_data['title'] . ' (' . $the_data['sales'] . ')');
         foreach ($years as $year => $value) {
             if ($year != $this->year) {
                 continue;
             }
             for ($i = 12; $i >= 1; $i--) {
                 if ($i > 1) {
                     $prev_month_data = $the_data['sales_by_month'][$year][$i - 1];
                     $color = $prev_month_data >= $the_data['sales_by_month'][$year][$i] ? 'red' : 'green';
                 } else {
                     $color = 'black';
                 }
                 $the_row[] = '<span style="color:' . $color . ';">' . $the_data['sales_by_month'][$year][$i] . '</span>';
             }
         }
         $table_data[] = $the_row;
     }
     $menu = '';
     $menu .= '<ul class="subsubsub">';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y')) . '" class="' . ($this->year == date('Y') ? 'current' : '') . '">' . date('Y') . '</a> | </li>';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y') - 1) . '" class="' . ($this->year == date('Y') - 1 ? 'current' : '') . '">' . (date('Y') - 1) . '</a> | </li>';
     $menu .= '</ul>';
     $menu .= '<br class="clear">';
     return '<p>' . $menu . '</p>' . wcj_get_table_html($table_data, array('table_class' => 'widefat'));
 }
 /**
  * create_export_tool.
  *
  * @version 2.5.9
  * @since   2.4.8
  */
 function create_export_tool($tool_id)
 {
     $data = $this->export($tool_id);
     echo $this->get_tool_header_html('export_' . $tool_id);
     echo '<form method="post" action="">';
     echo '<p>' . $this->export_filter_fields($tool_id) . '</p>';
     echo '<p>';
     echo '<button class="button-primary" type="submit" name="wcj_export" value="' . $tool_id . '">' . __('Download CSV', 'woocommerce-jetpack') . '</button>';
     echo ' ';
     echo '<button class="button-primary" type="submit" name="wcj_export_xml" value="' . $tool_id . '">' . __('Download XML', 'woocommerce-jetpack') . '</button>';
     echo '<button style="float:right;margin-right:10px;" class="button-primary" type="submit" name="wcj_export_filter" value="' . $tool_id . '">' . __('Filter by All Fields', 'woocommerce-jetpack') . '</button>';
     echo '<input style="float:right;margin-right:10px;" type="text" name="wcj_export_filter_all_columns" value="' . (isset($_POST['wcj_export_filter_all_columns']) ? $_POST['wcj_export_filter_all_columns'] : '') . '">';
     echo '</p>';
     echo '</form>';
     echo is_array($data) ? wcj_get_table_html($data, array('table_class' => 'widefat striped')) : $data;
 }
 /**
  * create_local_product_input_fields_meta_box.
  *
  * @version 2.2.9
  */
 public function create_local_product_input_fields_meta_box()
 {
     $meta_box_id = 'product_input_fields';
     $meta_box_desc = __('Product Input Fields', 'woocommerce-jetpack');
     $options = $this->get_options();
     // Get total number
     $current_post_id = get_the_ID();
     $option_name = 'wcj_' . $meta_box_id . '_local_total_number';
     // If none total number set - check for the default
     if (!($total_number = apply_filters('booster_get_option', 1, get_post_meta($current_post_id, '_' . $option_name, true)))) {
         $total_number = apply_filters('booster_get_option', 1, get_option('wcj_' . $meta_box_id . '_local_total_number_default', 1));
     }
     // Start html
     $html = '';
     // Total number
     $is_disabled = apply_filters('booster_get_message', '', 'readonly_string');
     $is_disabled_message = apply_filters('booster_get_message', '', 'desc');
     $html .= '<table>';
     $html .= '<tr>';
     $html .= '<th>';
     $html .= __('Total number of ', 'woocommerce-jetpack') . $meta_box_desc;
     $html .= '</th>';
     $html .= '<td>';
     $html .= '<input type="number" id="' . $option_name . '" name="' . $option_name . '" value="' . $total_number . '" ' . $is_disabled . '>';
     $html .= '</td>';
     $html .= '<td>';
     $html .= __('Click "Update" product after you change this number.', 'woocommerce-jetpack') . '<br>' . $is_disabled_message;
     $html .= '</td>';
     $html .= '</td>';
     $html .= '</tr>';
     $html .= '</table>';
     // The options
     //		$html .= '<h4>' . $meta_box_desc . '</h4>';
     for ($i = 1; $i <= $total_number; $i++) {
         $data = array();
         $html .= '<hr>';
         $html .= '<h4>' . __('Product Input Field', 'woocommerce-jetpack') . ' #' . $i . '</h4>';
         foreach ($options as $option) {
             $option_id = $option['id'] . $i;
             $option_value = get_post_meta($current_post_id, '_' . $option_id, true);
             if (!metadata_exists('post', $current_post_id, '_' . $option_id)) {
                 $option_value = $option['default'];
             }
             if ('checkbox' === $option['type']) {
                 $is_checked = checked($option_value, 'on', false);
             }
             $select_options_html = '';
             if ('select' === $option['type']) {
                 foreach ($option['options'] as $select_option_id => $select_option_label) {
                     $select_options_html .= '<option value="' . $select_option_id . '"' . selected($option_value, $select_option_id, false) . '>' . $select_option_label . '</option>';
                 }
             }
             switch ($option['type']) {
                 case 'number':
                 case 'text':
                     $the_field = '<input type="' . $option['type'] . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '">';
                     break;
                 case 'textarea':
                     $the_field = '<textarea style="width:100%;" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</textarea>';
                     break;
                 case 'checkbox':
                     $the_field = '<input class="checkbox" type="checkbox" name="' . $option_id . '" id="' . $option_id . '" ' . $is_checked . ' />';
                     break;
                 case 'select':
                     $the_field = '<select id="' . $option_id . '" name="' . $option_id . '">' . $select_options_html . '</select>';
                     break;
             }
             $data[] = array(isset($option['short_title']) ? $option['short_title'] : $option['title'], $the_field);
         }
         $html .= wcj_get_table_html($data, array('table_heading_type' => 'vertical', 'columns_styles' => array('text-align:right;')));
     }
     $html .= '<input type="hidden" name="woojetpack_' . $meta_box_id . '_save_post" value="woojetpack_' . $meta_box_id . '_save_post">';
     // Output
     echo $html;
 }
 /**
  * wcj_order_items_table.
  *
  * @version 2.5.9
  */
 function wcj_order_items_table($atts, $content = '')
 {
     $html = '';
     $the_order = $this->the_order;
     // Get columns
     $columns = explode('|', $atts['columns']);
     if (empty($columns)) {
         return '';
     }
     $columns_total_number = count($columns);
     // Check all possible args
     $columns_titles = '' == $atts['columns_titles'] ? array() : explode('|', $atts['columns_titles']);
     $columns_styles = '' == $atts['columns_styles'] ? array() : explode('|', $atts['columns_styles']);
     /* if ( $columns_total_number !== count( $columns_titles ) || $columns_total_number !== count( $columns_styles ) ) {
     			return __( 'Please recheck that there is the same number of columns in "columns", "columns_titles" and "columns_styles" attributes.', 'woocommerce-jetpack' );
     		} */
     // The Items
     $the_items = $the_order->get_items();
     // Shipping as item
     if ('' != $atts['shipping_as_item'] && $the_order->get_total_shipping() > 0) {
         $name = str_replace('%shipping_method_name%', $the_order->get_shipping_method(), $atts['shipping_as_item']);
         $total_shipping_tax_excl = $the_order->get_total_shipping();
         $shipping_tax = $the_order->get_shipping_tax();
         $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_shipping_tax_excl, 'line_total' => $total_shipping_tax_excl, 'line_tax' => $shipping_tax, 'line_subtotal_tax' => $shipping_tax));
     }
     // Discount as item
     if ('' != $atts['discount_as_item'] && $the_order->get_total_discount(true) > 0) {
         $name = $atts['discount_as_item'];
         $total_discount_tax_excl = $the_order->get_total_discount(true);
         $discount_tax = $the_order->get_total_discount(false) - $total_discount_tax_excl;
         /* if ( false != ( $the_tax = $this->wcj_order_get_cart_discount_tax() ) ) {
         				$total_discount_tax_excl -= $the_tax;
         				$discount_tax += $the_tax;
         			} */
         $total_discount_tax_excl *= -1;
         $discount_tax *= -1;
         $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_discount_tax_excl, 'line_total' => $total_discount_tax_excl, 'line_tax' => $discount_tax, 'line_subtotal_tax' => $discount_tax));
     }
     // Starting data[] by adding columns titles
     $data = array();
     foreach ($columns_titles as $column_title) {
         $data[0][] = $column_title;
     }
     // Items to data[]
     $item_counter = 0;
     foreach ($the_items as $item_id => $item) {
         $item['is_custom'] = isset($item['is_custom']) ? true : false;
         $the_product = true === $item['is_custom'] ? null : $the_order->get_product_from_item($item);
         $item_counter++;
         // Columns
         foreach ($columns as $column) {
             if (false !== ($pos = strpos($column, '='))) {
                 $column_param = substr($column, $pos + 1);
                 $column = substr($column, 0, $pos);
             }
             switch ($column) {
                 case 'item_debug':
                 case 'debug':
                     $data[$item_counter][] = print_r($item, true);
                     break;
                 case 'item_regular_price':
                 case 'product_regular_price':
                     $data[$item_counter][] = is_object($the_product) ? $this->wcj_price_shortcode($the_product->get_regular_price(), $atts) : '';
                     break;
                 case 'item_sale_price':
                 case 'product_sale_price':
                     $data[$item_counter][] = is_object($the_product) ? $this->wcj_price_shortcode($the_product->get_sale_price(), $atts) : '';
                     break;
                 case 'item_tax_class':
                 case 'tax_class':
                     $data[$item_counter][] = isset($item['tax_class']) ? $this->get_tax_class_name($item['tax_class']) : '';
                     break;
                 case 'item_number':
                     $data[$item_counter][] = $item_counter;
                     break;
                 case 'item_meta':
                     $data[$item_counter][] = wcj_get_order_item_meta_info($item_id, null, $this->the_order, false, $the_product);
                     break;
                 case 'item_name':
                 case 'product_name':
                     // "product_" because of possible variation
                     if (true === $item['is_custom']) {
                         $data[$item_counter][] = $item['name'];
                     } else {
                         $the_item_title = $item['name'];
                         // Variation (if needed)
                         if (0 != $item['variation_id'] && !in_array('item_variation', $columns)) {
                             $the_item_title .= '<div style="' . $atts['style_item_name_variation'] . '">';
                             if ('yes' === $atts['variation_as_metadata']) {
                                 $the_item_title .= wcj_get_order_item_meta_info($item_id, null, $this->the_order, true, $the_product);
                             } elseif (is_object($the_product) && $the_product->is_type('variation')) {
                                 $the_item_title .= str_replace('pa_', '', urldecode($the_product->get_formatted_variation_attributes(true)));
                                 // todo - do we need pa_ replacement?
                             }
                             $the_item_title .= '</div>';
                         }
                         // "WooCommerce TM Extra Product Options" plugin options
                         // todo - this will show options prices in shop's default currency only (must use 'price_per_currency' to show prices in order's currency).
                         if (isset($item['tmcartepo_data'])) {
                             $options = unserialize($item['tmcartepo_data']);
                             $options_prices = array();
                             //								$order_currency = $the_order->get_order_currency();
                             foreach ($options as $option) {
                                 /* if ( isset( $option['price_per_currency'][ $order_currency ] ) ) {
                                 				$options_prices[] = $this->wcj_price_shortcode( $option['price_per_currency'][ $order_currency ], $atts );
                                 			} */
                                 $option_info = '';
                                 if (isset($option['name']) && '' != $option['name']) {
                                     $option_info .= $option['name'] . ': ';
                                 }
                                 if (isset($option['value']) && '' != $option['value']) {
                                     $option_info .= $option['value'];
                                 }
                                 if (isset($option['price']) && 'yes' === $atts['wc_extra_product_options_show_price']) {
                                     // todo - wc_extra_product_options_show_price is temporary, until price_per_currency issue is solved
                                     $option_info .= $option['price'] > 0 ? ' +' . wc_price($option['price']) : ' ' . wc_price($option['price']);
                                 }
                                 if ('' != $option_info) {
                                     $options_prices[] = $option_info;
                                 }
                             }
                             $the_item_title .= '<div style="' . $atts['style_item_name_variation'] . '">' . implode('<br>', $options_prices) . '</div>';
                         }
                         $data[$item_counter][] = $the_item_title;
                     }
                     break;
                 case 'item_product_input_fields':
                     $data[$item_counter][] = wcj_get_product_input_fields($item);
                     break;
                 case 'item_key':
                     if (isset($column_param) && '' != $column_param && isset($item[$column_param])) {
                         $maybe_unserialized_value = maybe_unserialize($item[$column_param]);
                         if (is_array($maybe_unserialized_value)) {
                             $data[$item_counter][] = isset($maybe_unserialized_value['name']) ? $maybe_unserialized_value['name'] : '';
                         } else {
                             $data[$item_counter][] = $maybe_unserialized_value;
                         }
                     } else {
                         $data[$item_counter][] = '';
                     }
                     break;
                 case 'item_attribute':
                 case 'product_attribute':
                     if (isset($column_param) && '' != $column_param && is_object($the_product)) {
                         $data[$item_counter][] = $the_product->get_attribute($column_param);
                     } else {
                         $data[$item_counter][] = '';
                     }
                     break;
                 case 'item_excerpt':
                 case 'product_excerpt':
                     if (true === $item['is_custom']) {
                         $data[$item_counter][] = '';
                     } else {
                         global $post;
                         $post = get_post($item['product_id']);
                         setup_postdata($post);
                         $the_excerpt = get_the_excerpt();
                         wp_reset_postdata();
                         $data[$item_counter][] = $the_excerpt;
                     }
                     break;
                 case 'item_short_description':
                 case 'product_short_description':
                     $data[$item_counter][] = true === $item['is_custom'] ? '' : $this->the_product->post->post_excerpt;
                     break;
                 case 'item_variation':
                 case 'product_variation':
                     if (0 != $item['variation_id']) {
                         if ('yes' === $atts['variation_as_metadata']) {
                             $data[$item_counter][] = wcj_get_order_item_meta_info($item_id, null, $this->the_order, true, $the_product);
                         } elseif (is_object($the_product) && $the_product->is_type('variation')) {
                             $data[$item_counter][] = str_replace('pa_', '', urldecode($the_product->get_formatted_variation_attributes(true)));
                             // todo - do we need pa_ replacement?
                         }
                     } else {
                         $data[$item_counter][] = '';
                     }
                     break;
                 case 'item_thumbnail':
                 case 'product_thumbnail':
                     //						$data[ $item_counter ][] = $the_product->get_image();
                     $image_id = true === $item['is_custom'] || !is_object($the_product) ? 0 : $the_product->get_image_id();
                     $image_src = 0 != $image_id ? wp_get_attachment_image_src($image_id) : wc_placeholder_img_src();
                     if (is_array($image_src)) {
                         $image_src = $image_src[0];
                     }
                     $maybe_width = 0 != $atts['product_image_width'] ? ' width="' . $atts['product_image_width'] . '"' : '';
                     $maybe_height = 0 != $atts['product_image_height'] ? ' height="' . $atts['product_image_height'] . '"' : '';
                     $data[$item_counter][] = '<img src="' . $image_src . '"' . $maybe_width . $maybe_height . '>';
                     break;
                 case 'item_sku':
                 case 'product_sku':
                     $data[$item_counter][] = true === $item['is_custom'] || !is_object($the_product) ? '' : $the_product->get_sku();
                     break;
                 case 'item_quantity':
                     $data[$item_counter][] = $atts['quantity_prefix'] . $item['qty'];
                     break;
                 case 'item_total_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, false, true), $atts);
                     break;
                 case 'item_total_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, true, true), $atts);
                     break;
                 case 'item_subtotal_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, false, true), $atts);
                     break;
                 case 'item_subtotal_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, true, true), $atts);
                     break;
                 case 'item_tax':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_tax($item, true), $atts);
                     break;
                 case 'line_total_tax_excl':
                     $line_total_tax_excl = $the_order->get_line_total($item, false, true);
                     $line_total_tax_excl = apply_filters('wcj_line_total_tax_excl', $line_total_tax_excl, $the_order);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_total_tax_excl, $atts);
                     break;
                 case 'line_total_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_total($item, true, true), $atts);
                     break;
                 case 'line_subtotal_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, false, true), $atts);
                     break;
                 case 'line_subtotal_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, true, true), $atts);
                     break;
                 case 'line_tax':
                     $line_tax = $the_order->get_line_tax($item);
                     $line_tax = apply_filters('wcj_line_tax', $line_tax, $the_order);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_tax, $atts);
                     break;
                 case 'line_subtax':
                     $line_subtax = $the_order->get_line_subtotal($item, true, false) - $the_order->get_line_subtotal($item, false, false);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_subtax, $atts);
                     break;
                 case 'item_tax_percent':
                 case 'line_tax_percent':
                     $item_total = $the_order->get_item_total($item, false, false);
                     $item_tax_percent = 0 != $item_total ? $the_order->get_item_tax($item, false) / $item_total * 100 : 0;
                     $item_tax_percent = apply_filters('wcj_line_tax_percent', $item_tax_percent, $the_order);
                     $data[$item_counter][] = sprintf($atts['tax_percent_format'], $item_tax_percent);
                     /* $tax_labels = array();
                     			foreach ( $the_order->get_taxes() as $the_tax ) {
                     				$tax_labels[] = $the_tax['label'];
                     			}
                     			$data[ $item_counter ][] = implode( ', ', $tax_labels ); */
                     break;
                     /* case 'line_tax_percent':
                     			$line_total = $the_order->get_line_total( $item, false, true );
                     			$line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0;
                     			$line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order );
                     			$data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent );
                     			break; */
                 /* case 'line_tax_percent':
                 			$line_total = $the_order->get_line_total( $item, false, true );
                 			$line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0;
                 			$line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order );
                 			$data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent );
                 			break; */
                 case 'item_weight':
                 case 'product_weight':
                     $data[$item_counter][] = true === $item['is_custom'] || !is_object($the_product) ? '' : $the_product->get_weight();
                     break;
                 case 'item_width':
                 case 'product_width':
                     $data[$item_counter][] = true === $item['is_custom'] || !is_object($the_product) ? '' : $the_product->get_width();
                     break;
                 case 'item_height':
                 case 'product_height':
                     $data[$item_counter][] = true === $item['is_custom'] || !is_object($the_product) ? '' : $the_product->get_height();
                     break;
                 case 'item_length':
                 case 'product_length':
                     $data[$item_counter][] = true === $item['is_custom'] || !is_object($the_product) ? '' : $the_product->get_length();
                     break;
                 default:
                     $data[$item_counter][] = '';
                     // $column;
             }
         }
     }
     $html = wcj_get_table_html($data, array('table_class' => $atts['table_class'], 'table_heading_type' => 'horizontal', 'columns_classes' => array(), 'columns_styles' => $columns_styles));
     return $html;
 }
 /**
  * create_meta_box.
  *
  * @version 2.4.5
  * @since   2.4.5
  * @todo    min_profit
  */
 function create_meta_box()
 {
     parent::create_meta_box();
     // Report
     $main_product_id = get_the_ID();
     $_product = wc_get_product($main_product_id);
     $products = array();
     if ($_product->is_type('variable')) {
         $available_variations = $_product->get_available_variations();
         foreach ($available_variations as $variation) {
             $variation_product = wc_get_product($variation['variation_id']);
             $products[$variation['variation_id']] = ' (' . $variation_product->get_formatted_variation_attributes(true) . ')';
         }
     } else {
         $products[$main_product_id] = '';
     }
     foreach ($products as $product_id => $desc) {
         $purchase_price = wc_get_product_purchase_price($product_id);
         if (0 != $purchase_price) {
             $the_product = wc_get_product($product_id);
             $the_price = $the_product->get_price();
             if (0 != $the_price) {
                 $the_profit = $the_price - $purchase_price;
                 $table_data = array();
                 $table_data[] = array(__('Selling', 'woocommerce-jetpack'), wc_price($the_price));
                 $table_data[] = array(__('Buying', 'woocommerce-jetpack'), wc_price($purchase_price));
                 $table_data[] = array(__('Profit', 'woocommerce-jetpack'), wc_price($the_profit) . sprintf(' (%0.2f %%)', $the_profit / $purchase_price * 100));
                 //						. sprintf( ' (%0.2f %%)', ( $the_profit / $the_price * 100 ) ) );
                 /* $the_min_profit = $purchase_price * 0.25;
                 			$the_min_price = $purchase_price * 1.25;
                 			$html .= __( 'Min Profit', 'woocommerce-jetpack' );
                 			$html .= wc_price( $the_min_profit ) . ' ' . __( 'at', 'woocommerce-jetpack' ) . ' ' . wc_price( $the_min_price ); */
                 $html = '';
                 $html .= '<h5>' . __('Report', 'woocommerce-jetpack') . $desc . '</h5>';
                 $html .= wcj_get_table_html($table_data, array('table_heading_type' => 'none', 'table_class' => 'widefat striped', 'table_style' => 'width:50%;min-width:300px;', 'columns_styles' => array('width:33%;')));
                 echo $html;
             }
         }
     }
 }
 /**
  * create_eu_countries_vat_rates_tool.
  *
  * @version 2.3.10
  * @since   2.3.10
  */
 function create_eu_countries_vat_rates_tool($header_html)
 {
     $the_tool_html = '';
     $the_tool_html .= $header_html;
     //		$the_tool_html .= '<h4>' . __( 'Settings', 'woocommerce-jetpack' ) . '</h4>';
     $data = array();
     $the_name = isset($_POST['wcj_tax_name']) ? $_POST['wcj_tax_name'] : __('VAT', 'woocommerce');
     $data[] = array(__('Name', 'woocommerce-jetpack'), '<input class="input-text" type="text" name="wcj_tax_name" value="' . $the_name . '">');
     $data[] = array('', '<input class="button-primary" type="submit" name="add_eu_countries_vat_rates" value="' . __('Add EU Countries VAT Rates', 'woocommerce-jetpack') . '">' . ' ' . __('Note: will add duplicates.', 'woocommerce-jetpack'));
     $the_tool_html .= '<p>';
     $the_tool_html .= '<form method="post" action="">';
     $the_tool_html .= wcj_get_table_html($data, array('table_heading_type' => 'vertical'));
     $the_tool_html .= '</form>';
     $the_tool_html .= '</p>';
     $the_tool_html .= '<h4>' . __('List of EU VAT rates to be added', 'woocommerce-jetpack') . '</h4>';
     $eu_vat_rates = wcj_get_european_union_countries_with_vat();
     $data = array();
     $data[] = array('', __('Country', 'woocommerce-jetpack'), __('Rate', 'woocommerce-jetpack'));
     $i = 1;
     foreach ($eu_vat_rates as $country => $rate) {
         $data[] = array($i++, $country . ' - ' . wcj_get_country_name_by_code($country), $rate . '%');
     }
     $the_tool_html .= wcj_get_table_html($data, array('table_class' => 'widefat', 'table_style' => 'width:50%;min-width:300px;'));
     $the_tool_html .= '<h4>' . __('Current standard tax rates', 'woocommerce-jetpack') . '</h4>';
     $standard_tax_rates = wcj_get_rates_for_tax_class('');
     $data = array();
     $data[] = array('', __('Country', 'woocommerce-jetpack'), __('Rate', 'woocommerce-jetpack'), __('Name', 'woocommerce-jetpack'));
     $i = 1;
     foreach ($standard_tax_rates as $tax_rate_object) {
         $data[] = array($i++, $tax_rate_object->tax_rate_country . ' - ' . wcj_get_country_name_by_code($tax_rate_object->tax_rate_country), $tax_rate_object->tax_rate . '%', $tax_rate_object->tax_rate_name);
     }
     $the_tool_html .= wcj_get_table_html($data, array('table_class' => 'widefat', 'table_style' => 'width:75%;min-width:300px;'));
     echo $the_tool_html;
 }
        /**
         * Add Renumerate Invoices tool to WooCommerce menu (the content).
         *
         * @version 2.3.10
         */
        function create_renumerate_invoices_tool()
        {
            $result_message = '';
            $renumerate_result = '';
            $the_invoice_type = !empty($_POST['invoice_type']) ? $_POST['invoice_type'] : 'invoice';
            $the_start_number = !empty($_POST['start_number']) ? $_POST['start_number'] : 0;
            $the_start_date = !empty($_POST['start_date']) ? $_POST['start_date'] : '';
            $the_end_date = !empty($_POST['end_date']) ? $_POST['end_date'] : '';
            $the_order_statuses = !empty($_POST['order_statuses']) ? $_POST['order_statuses'] : array();
            $the_delete_all = isset($_POST['delete_all']) ? true : false;
            if (isset($_POST['renumerate_invoices'])) {
                if (!empty($the_order_statuses)) {
                    $renumerate_result = $this->renumerate_invoices($the_invoice_type, $the_start_number, $the_start_date, $the_end_date, $the_order_statuses, $the_delete_all);
                    $result_message = '<div class="updated"><p><strong>' . __('Invoices successfully renumerated!', 'woocommerce-jetpack') . '</strong></p></div>';
                } else {
                    $result_message = '<div class="error"><p><strong>' . __('Please select at least one order status.', 'woocommerce-jetpack') . '</strong></p></div>';
                }
                //$result_message .= '<p>' . $renumerate_result . '</p>';
            }
            ?>
<div>
			<h2><?php 
            echo __('Booster - Renumerate Invoices', 'woocommerce-jetpack');
            ?>
</h2>
			<p><?php 
            echo __('The tool renumerates invoices from choosen date. Invoice number format is set in WooCommerce > Settings > Booster > PDF Invoicing & Packing Slips > Numbering.', 'woocommerce-jetpack');
            ?>
</p>
			<?php 
            echo $result_message;
            ?>
			<p><form method="post" action="">
				<?php 
            // Start Date
            $data[] = array(__('Start Date', 'woocommerce-jetpack'), '<input class="input-text" display="date" type="text" name="start_date" value="' . $the_start_date . '">', '<em>' . __('Date to start renumerating. Leave blank to renumerate all invoices.', 'woocommerce-jetpack') . '</em>');
            // End Date
            $data[] = array(__('End Date', 'woocommerce-jetpack'), '<input class="input-text" display="date" type="text" name="end_date" value="' . $the_end_date . '">', '<em>' . __('Date to end renumerating. Leave blank to renumerate all invoices.', 'woocommerce-jetpack') . '</em>');
            // Number
            $data[] = array(__('Start Number', 'woocommerce-jetpack'), '<input class="input-text" type="text" name="start_number" value="' . $the_start_number . '">', '<em>' . __('Counter to start renumerating. Leave 0 to continue from current counter.', 'woocommerce-jetpack') . '</em>');
            // Delete All
            $data[] = array(__('Delete All', 'woocommerce-jetpack'), '<input type="checkbox" name="delete_all" value="" ' . checked($the_delete_all, true, false) . '>', '<em>' . __('Clear all invoices before renumerating.', 'woocommerce-jetpack') . '</em>');
            // Type
            $invoice_type_select_html = '<select name="invoice_type">';
            //$invoice_types = wcj_get_invoice_types();
            $invoice_types = wcj_get_enabled_invoice_types();
            foreach ($invoice_types as $invoice_type) {
                $invoice_type_select_html .= '<option value="' . $invoice_type['id'] . '" ' . selected($invoice_type['id'], $the_invoice_type, false) . '>' . $invoice_type['title'] . '</option>';
            }
            $invoice_type_select_html .= '</select>';
            $data[] = array(__('Document Type', 'woocommerce-jetpack'), $invoice_type_select_html, '');
            // Statuses
            $order_statuses_select_html = '<select id="order_statuses" name="order_statuses[]" multiple size="5">';
            $order_statuses = wcj_get_order_statuses(false);
            foreach ($order_statuses as $status => $desc) {
                //$order_statuses_select_html .= '<option value="' . $status . '">' . $desc . '</option>';
                $order_statuses_select_html .= '<option value="' . $status . '" ' . $this->wcj_multi_selected($status, $the_order_statuses) . '>' . $desc . '</option>';
            }
            $order_statuses_select_html .= '</select>';
            $data[] = array(__('Order Statuses', 'woocommerce-jetpack'), $order_statuses_select_html, '');
            // Button
            $data[] = array('<input class="button-primary" type="submit" name="renumerate_invoices" value="' . __('Renumerate invoices', 'woocommerce-jetpack') . '">', '', '');
            // Print all
            echo wcj_get_table_html($data, array('table_heading_type' => 'vertical'));
            ?>
			</form></p>
			<?php 
            if ('' != $renumerate_result) {
                echo '<h3>' . __('Results', 'woocommerce-jetpack') . '</h3>';
                echo '<p>' . $renumerate_result . '</p>';
            }
            ?>
		</div><?php 
        }
 /**
  * create_custom_tabs_meta_box.
  *
  * @version 2.2.9
  */
 public function create_custom_tabs_meta_box()
 {
     $current_post_id = get_the_ID();
     $option_name = 'wcj_custom_product_tabs_local_total_number';
     if (!($total_custom_tabs = get_post_meta($current_post_id, '_' . $option_name, true))) {
         $total_custom_tabs = apply_filters('wcj_get_option_filter', 1, get_option('wcj_custom_product_tabs_local_total_number_default', 1));
     }
     $html = '';
     $is_disabled = apply_filters('get_wc_jetpack_plus_message', '', 'readonly_string');
     $is_disabled_message = apply_filters('get_wc_jetpack_plus_message', '', 'desc');
     $html .= '<table>';
     $html .= '<tr>';
     $html .= '<th>';
     $html .= __('Total number of custom tabs', 'woocommerce-jetpack');
     $html .= '</th>';
     $html .= '<td>';
     $html .= '<input type="number" id="' . $option_name . '" name="' . $option_name . '" value="' . $total_custom_tabs . '" ' . $is_disabled . '>';
     $html .= '</td>';
     $html .= '<td>';
     $html .= __('Click "Update" product after you change this number.', 'woocommerce-jetpack') . '<br>' . $is_disabled_message;
     $html .= '</td>';
     $html .= '</td>';
     $html .= '</tr>';
     $html .= '</table>';
     $options = array(array('id' => 'wcj_custom_product_tabs_title_local_', 'title' => __('Title', 'woocommerce-jetpack'), 'type' => 'text'), array('id' => 'wcj_custom_product_tabs_content_local_', 'title' => __('Content', 'woocommerce-jetpack'), 'type' => 'textarea'), array('id' => 'wcj_custom_product_tabs_priority_local_', 'title' => __('Order', 'woocommerce-jetpack'), 'type' => 'number'));
     //		$html .= '<h4>' . __( 'Customize the tab(s)', 'woocommerce-jetpack' ) . '</h4>';
     for ($i = 1; $i <= $total_custom_tabs; $i++) {
         $data = array();
         $html .= '<hr>';
         $html .= '<h4>' . __('Custom Product Tab', 'woocommerce-jetpack') . ' #' . $i . '</h4>';
         foreach ($options as $option) {
             $option_id = $option['id'] . $i;
             $option_value = get_post_meta($current_post_id, '_' . $option_id, true);
             if (!$option_value && 'wcj_custom_product_tabs_priority_local_' == $option['id']) {
                 $option_value = 50;
             }
             switch ($option['type']) {
                 case 'number':
                 case 'text':
                     $the_field = '<input type="' . $option['type'] . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '">';
                     break;
                 case 'textarea':
                     $the_field = '<textarea class="short" rows="10" cols="40" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</textarea>';
                     break;
             }
             $data[] = array($option['title'], $the_field);
         }
         $html .= wcj_get_table_html($data, array('table_heading_type' => 'vertical'));
     }
     $html .= '<input type="hidden" name="woojetpack_custom_tabs_save_post" value="woojetpack_custom_tabs_save_post">';
     echo $html;
 }
 function get_monthly_sales_report()
 {
     $execution_time_start = microtime(true);
     $months_array = array('');
     $months_days_array = array(__('Days', 'woocommerce-jetpack'));
     $total_orders_array = array(__('Total Orders', 'woocommerce-jetpack'));
     $total_orders_average_array = array(__('Orders Average / Day', 'woocommerce-jetpack'));
     $total_orders_sum_array = array(__('Total Sum', 'woocommerce-jetpack'));
     $total_orders_sum_excl_tax_array = array(__('Total Sum (excl. TAX)', 'woocommerce-jetpack'));
     $total_orders_sum_average_order_array = array(__('Average / Order (excl. TAX)', 'woocommerce-jetpack'));
     $total_orders_sum_average_array = array(__('Average / Day (excl. TAX)', 'woocommerce-jetpack'));
     $currency_rates_array = array(__('Currency Rates', 'woocommerce-jetpack'));
     $total_months_days = 0;
     $total_orders_total = 0;
     $total_orders_sum_total = 0;
     $total_orders_sum_excl_tax_total = 0;
     $order_currencies_array = array();
     $report_currency = isset($_GET['currency']) && 'merge' != $_GET['currency'] ? $_GET['currency'] : get_woocommerce_currency();
     $block_size = 96;
     $table_data = array();
     for ($i = 1; $i <= 12; $i++) {
         $current_months_averages = array();
         $total_orders = 0;
         $total_orders_sum = 0;
         $total_orders_sum_excl_tax = 0;
         $offset = 0;
         $day_for_average = $i == date('m') && $this->year == date('Y') ? date('d') - 1 : date('t', strtotime($this->year . '-' . sprintf('%02d', $i) . '-' . '01'));
         if (0 == $day_for_average) {
             $months_array[] = date_i18n('F', mktime(0, 0, 0, $i, 1, $this->year));
             $months_days_array[] = '-';
             $total_orders_array[] = '-';
             $total_orders_average_array[] = '-';
             $total_orders_sum_array[] = '-';
             $total_orders_sum_excl_tax_array[] = '-';
             $total_orders_sum_average_order_array[] = '-';
             $total_orders_sum_average_array[] = '-';
             $currency_rates_array[] = '';
             continue;
         }
         while (true) {
             $args_orders = array('post_type' => 'shop_order', 'post_status' => 'wc-completed', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset, 'date_query' => array('after' => array('year' => $this->year, 'month' => $i, 'day' => 1), 'before' => array('year' => $this->year, 'month' => $i, 'day' => $day_for_average), 'inclusive' => true));
             $loop_orders = new WP_Query($args_orders);
             if (!$loop_orders->have_posts()) {
                 break;
             }
             while ($loop_orders->have_posts()) {
                 $loop_orders->the_post();
                 $order_id = $loop_orders->post->ID;
                 $order = new WC_Order($order_id);
                 $order_currency = $order->get_order_currency();
                 if (!isset($order_currencies_array[$order_currency])) {
                     $order_currencies_array[$order_currency] = 0;
                 }
                 $order_currencies_array[$order_currency]++;
                 $total_orders++;
                 $order_total = $order->get_total();
                 $order_total_excl_tax = $order->get_total() - $order->get_total_tax();
                 if (!isset($current_months_averages[$order_currency][$report_currency])) {
                     $start_date = $this->year . '-' . sprintf('%02d', $i) . '-' . '01';
                     $end_date = date('Y-m-t', strtotime($start_date));
                     $the_rate = $this->get_exchange_rate_average($order_currency, $report_currency, $start_date, $end_date);
                     if (false === $the_rate) {
                         // Try previous month
                         $start_date_prev_month = date('Y-m-d', strtotime('first day of last month', strtotime($start_date)));
                         $end_date_prev_month = date('Y-m-t', strtotime($start_date_prev_month));
                         $the_rate = $this->get_exchange_rate_average($order_currency, $report_currency, $start_date_prev_month, $end_date_prev_month);
                         if (false === $the_rate) {
                             return '<p>' . sprintf(__('Error getting currency rate for %s', 'woocommerce-jetpack'), $order_currency . $report_currency) . '</p>';
                         }
                     }
                     $current_months_averages[$order_currency][$report_currency] = $the_rate;
                 }
                 $total_orders_sum += $order_total * $current_months_averages[$order_currency][$report_currency];
                 $total_orders_sum_excl_tax += $order_total_excl_tax * $current_months_averages[$order_currency][$report_currency];
             }
             $offset += $block_size;
         }
         // Month Name
         $months_array[] = date_i18n('F', mktime(0, 0, 0, $i, 1, $this->year));
         // Month Days
         $months_days_array[] = date('m') >= $i || $this->year != date('Y') ? $day_for_average : '-';
         $total_months_days += date('m') >= $i || $this->year != date('Y') ? $day_for_average : 0;
         // Sales
         $total_orders_array[] = $total_orders > 0 ? $total_orders : '-';
         $total_orders_total += $total_orders;
         // Sales Average
         $average_sales_result = $total_orders / $day_for_average;
         $total_orders_average_array[] = $average_sales_result > 0 ? number_format($average_sales_result, 2, '.', ',') : '-';
         // Sum
         $total_orders_sum_array[] = $total_orders_sum > 0 ? $report_currency . ' ' . number_format($total_orders_sum, 2, '.', ',') : '-';
         $total_orders_sum_total += $total_orders_sum;
         // Sum excl. Tax
         //if ( $total_orders_sum != $total_orders_sum_excl_tax) {
         $total_orders_sum_excl_tax_array[] = $total_orders_sum_excl_tax > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax, 2, '.', ',') : '-';
         $total_orders_sum_excl_tax_total += $total_orders_sum_excl_tax;
         //}
         // Order Average
         $total_orders_sum_average_order_array[] = $total_orders_sum_excl_tax > 0 && $total_orders > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax / $total_orders, 2, '.', ',') : '-';
         // Sum Average
         $average_result = $total_orders_sum_excl_tax / $day_for_average;
         $total_orders_sum_average_array[] = $average_result > 0 ? $report_currency . ' ' . number_format($average_result, 2, '.', ',') : '-';
         // Currency Rates
         //			if ( isset( $_GET['show_rates'] ) ) {
         ksort($current_months_averages, true);
         //				$currency_rates_html = '<pre style="font-size:8px;">' . print_r( $current_months_averages, true ) . '</pre>';
         $currency_rates_html = '<pre style="font-size:x-small;">';
         foreach ($current_months_averages as $currency_from => $currencies_to) {
             foreach ($currencies_to as $currency_to => $rate) {
                 if ($currency_from != $currency_to) {
                     $currency_rates_html .= $currency_from . $currency_to . '~' . number_format($rate, 4) . '<br>';
                 }
             }
         }
         $currency_rates_html .= '</pre>';
         //			}
         $currency_rates_array[] = $currency_rates_html;
     }
     // Totals
     $months_array[] = __('Totals', 'woocommerce-jetpack');
     $months_days_array[] = $total_months_days;
     $total_orders_array[] = $total_orders_total;
     $total_orders_average_array[] = $total_months_days > 0 ? number_format($total_orders_total / $total_months_days, 2, '.', ',') : '-';
     $total_orders_sum_array[] = $report_currency . ' ' . number_format($total_orders_sum_total, 2, '.', ',');
     $total_orders_sum_excl_tax_array[] = $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total, 2, '.', ',');
     $total_orders_sum_average_order_array[] = $total_orders_total > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total / $total_orders_total, 2, '.', ',') : '-';
     $total_orders_sum_average_array[] = $total_months_days > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total / $total_months_days, 2, '.', ',') : '-';
     $currency_rates_array[] = '';
     // Table
     $table_data[] = $months_array;
     $table_data[] = $months_days_array;
     $table_data[] = $total_orders_array;
     $table_data[] = $total_orders_average_array;
     $table_data[] = $total_orders_sum_array;
     $table_data[] = $total_orders_sum_excl_tax_array;
     $table_data[] = $total_orders_sum_average_order_array;
     $table_data[] = $total_orders_sum_average_array;
     $table_data[] = $currency_rates_array;
     /* foreach ( $order_currencies_array as $order_currency => $total_currency_orders ) {
     			$table_data[] = array( $order_currency . ' (' . $total_currency_orders . ')' );
     		} */
     $execution_time_end = microtime(true);
     // HTML
     $html = '';
     $menu = '';
     $menu .= '<ul class="subsubsub">';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y')) . '" class="' . ($this->year == date('Y') ? 'current' : '') . '">' . date('Y') . '</a> | </li>';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y') - 1) . '" class="' . ($this->year == date('Y') - 1 ? 'current' : '') . '">' . (date('Y') - 1) . '</a> | </li>';
     $menu .= '</ul>';
     $menu .= '<br class="clear">';
     $html .= $menu;
     $html .= '<h4>' . __('Report currency', 'woocommerce-jetpack') . ': ' . $report_currency . '</h4>';
     $months_styles = array();
     for ($i = 1; $i <= 12; $i++) {
         $months_styles[] = 'width:6%;';
     }
     $html .= wcj_get_table_html($table_data, array('table_class' => 'widefat striped', 'table_heading_type' => 'horizontal', 'columns_styles' => array_merge(array('width:16%;'), $months_styles, array('width:12%;font-weight:bold;'))));
     $html .= '<p style="font-size:x-small;"><em>' . sprintf(__('Report generated in: %s s', 'woocommerce-jetpack'), number_format($execution_time_end - $execution_time_start, 2, '.', ',')) . '</em></p>';
     $html .= '<form method="post" action="">' . '<input name="wcj_reset_currency_rates" type="submit" class="button button-primary" value="' . __('Reset Currency Rates', 'woocommerce-jetpack') . '">' . '</form>';
     //		$html .= '<pre>' . print_r( get_option( 'wcj_reports_currency_rates' ), true ) . '</pre>';
     return $html;
 }
 /**
  * add_my_products_content_my_account_page.
  *
  * @version 2.5.7
  * @since   2.5.2
  */
 function add_my_products_content_my_account_page()
 {
     /* if ( ! isset( $_GET['wcj-my-products'] ) ) {
     			return;
     		} */
     $user_ID = get_current_user_id();
     if (0 == $user_ID) {
         return;
     }
     if (isset($_GET['wcj_delete_product'])) {
         $product_id = $_GET['wcj_delete_product'];
         $post_author_id = get_post_field('post_author', $product_id);
         if ($user_ID != $post_author_id) {
             echo '<p>' . __('Wrong user ID!', 'woocommerce-jetpack') . '</p>';
         } else {
             wp_delete_post($product_id, true);
         }
     }
     if (isset($_GET['wcj_edit_product'])) {
         $product_id = $_GET['wcj_edit_product'];
         $post_author_id = get_post_field('post_author', $product_id);
         if ($user_ID != $post_author_id) {
             echo '<p>' . __('Wrong user ID!', 'woocommerce-jetpack') . '</p>';
         } else {
             echo do_shortcode('[wcj_product_add_new product_id="' . $product_id . '"]');
         }
     }
     $offset = 0;
     $block_size = 96;
     $products = array();
     while (true) {
         $args = array('post_type' => 'product', 'post_status' => 'any', 'posts_per_page' => $block_size, 'offset' => $offset, 'orderby' => 'date', 'order' => 'DESC', 'author' => $user_ID);
         $loop = new WP_Query($args);
         if (!$loop->have_posts()) {
             break;
         }
         while ($loop->have_posts()) {
             $loop->the_post();
             $products[strval($loop->post->ID)] = array('title' => get_the_title($loop->post->ID), 'status' => get_post_status($loop->post->ID));
         }
         $offset += $block_size;
     }
     wp_reset_postdata();
     if (0 != count($products)) {
         //			echo '<h2>' . __( 'My Products', 'woocommerce-jetpack' ) . '</h2>';
         $table_data = array();
         $table_data[] = array('', __('Status', 'woocommerce-jetpack'), __('Title', 'woocommerce-jetpack'), __('Actions', 'woocommerce-jetpack'));
         $i = 0;
         foreach ($products as $_product_id => $_product_data) {
             $i++;
             $table_data[] = array(get_the_post_thumbnail($_product_id, array(25, 25)), '<code>' . $_product_data['status'] . '</code>', $_product_data['title'], '<a class="button" href="' . add_query_arg('wcj_edit_product', $_product_id, remove_query_arg(array('wcj_edit_product_image_delete', 'wcj_delete_product'))) . '">' . __('Edit', 'woocommerce-jetpack') . '</a>' . ' ' . '<a class="button" href="' . add_query_arg('wcj_delete_product', $_product_id, remove_query_arg(array('wcj_edit_product_image_delete', 'wcj_edit_product'))) . '" onclick="return confirm(\'' . __('Are you sure?', 'woocommerce-jetpack') . '\')">' . __('Delete', 'woocommerce-jetpack') . '</a>');
         }
         echo wcj_get_table_html($table_data, array('table_class' => 'shop_table shop_table_responsive my_account_orders'));
     }
 }
 /**
  * wcj_order_items_table.
  */
 function wcj_order_items_table($atts, $content = '')
 {
     $html = '';
     $the_order = $this->the_order;
     // Get columns
     $columns = explode('|', $atts['columns']);
     if (empty($columns)) {
         return '';
     }
     $columns_total_number = count($columns);
     // Check all possible args
     $columns_titles = '' == $atts['columns_titles'] ? array() : explode('|', $atts['columns_titles']);
     $columns_styles = '' == $atts['columns_styles'] ? array() : explode('|', $atts['columns_styles']);
     //if ( ! ( $columns_total_number === count( $columns_titles ) === count( $columns_styles ) ) ) return '';
     // The Items
     $the_items = $the_order->get_items();
     // Shipping as item
     if ('' != $atts['shipping_as_item'] && $the_order->get_total_shipping() > 0) {
         $name = str_replace('%shipping_method_name%', $the_order->get_shipping_method(), $atts['shipping_as_item']);
         $total_shipping_tax_excl = $the_order->get_total_shipping();
         $shipping_tax = $the_order->get_shipping_tax();
         $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_shipping_tax_excl, 'line_total' => $total_shipping_tax_excl, 'line_tax' => $shipping_tax, 'line_subtotal_tax' => $shipping_tax));
     }
     // Discount as item
     if ('' != $atts['discount_as_item'] && $the_order->get_total_discount(true) > 0) {
         $name = $atts['discount_as_item'];
         $total_discount_tax_excl = $the_order->get_total_discount(true);
         $discount_tax = $the_order->get_total_discount(false) - $total_discount_tax_excl;
         if (false != ($the_tax = $this->wcj_order_get_cart_discount_tax())) {
             $total_discount_tax_excl -= $the_tax;
             $discount_tax += $the_tax;
         }
         $total_discount_tax_excl *= -1;
         $discount_tax *= -1;
         $the_items = $this->add_item($the_items, array('name' => $name, 'qty' => 1, 'line_subtotal' => $total_discount_tax_excl, 'line_total' => $total_discount_tax_excl, 'line_tax' => $discount_tax, 'line_subtotal_tax' => $discount_tax));
     }
     // Starting data[] by adding columns titles
     $data = array();
     foreach ($columns_titles as $column_title) {
         $data[0][] = $column_title;
     }
     // Items to data[]
     $item_counter = 0;
     foreach ($the_items as $item) {
         $item['is_custom'] = isset($item['is_custom']) ? true : false;
         $the_product = true === $item['is_custom'] ? null : $the_order->get_product_from_item($item);
         $item_counter++;
         // Columns
         foreach ($columns as $column) {
             switch ($column) {
                 case 'item_number':
                     $data[$item_counter][] = $item_counter;
                     break;
                 case 'item_name':
                     //$data[ $item_counter ][] = ( true === $item['is_custom'] ) ? $item['name'] : $the_product->get_title();
                     if (true === $item['is_custom']) {
                         $data[$item_counter][] = $item['name'];
                     } else {
                         $the_item_title = $the_product->get_title();
                         // Variation (if needed)
                         if ($the_product->is_type('variation') && !in_array('item_variation', $columns)) {
                             $the_item_title .= '<div style="font-size:smaller;">' . wc_get_formatted_variation($the_product->variation_data, true) . '</div>';
                         }
                         $data[$item_counter][] = $the_item_title;
                     }
                     break;
                 case 'item_variation':
                     $data[$item_counter][] = $the_product->is_type('variation') ? wc_get_formatted_variation($the_product->variation_data, true) : '';
                     break;
                 case 'item_thumbnail':
                     //$data[ $item_counter ][] = $the_product->get_image();
                     $image_id = true === $item['is_custom'] ? 0 : $the_product->get_image_id();
                     $image_src = 0 != $image_id ? wp_get_attachment_image_src($image_id) : wc_placeholder_img_src();
                     if (is_array($image_src)) {
                         $image_src = $image_src[0];
                     }
                     $maybe_width = 0 != $atts['item_image_width'] ? ' width="' . $atts['item_image_width'] . '"' : '';
                     $maybe_height = 0 != $atts['item_image_height'] ? ' height="' . $atts['item_image_height'] . '"' : '';
                     $data[$item_counter][] = '<img src="' . $image_src . '"' . $maybe_width . $maybe_height . '>';
                     break;
                 case 'item_sku':
                     $data[$item_counter][] = true === $item['is_custom'] ? '' : $the_product->get_sku();
                     break;
                 case 'item_quantity':
                     $data[$item_counter][] = $item['qty'];
                     break;
                 case 'item_total_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, false, true), $atts);
                     break;
                 case 'item_total_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_total($item, true, true), $atts);
                     break;
                 case 'item_subtotal_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, false, true), $atts);
                     break;
                 case 'item_subtotal_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_subtotal($item, true, true), $atts);
                     break;
                 case 'item_tax':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_item_tax($item, true), $atts);
                     break;
                 case 'line_total_tax_excl':
                     $line_total_tax_excl = $the_order->get_line_total($item, false, true);
                     $line_total_tax_excl = apply_filters('wcj_line_total_tax_excl', $line_total_tax_excl, $the_order);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_total_tax_excl, $atts);
                     break;
                 case 'line_total_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_total($item, true, true), $atts);
                     break;
                 case 'line_subtotal_tax_excl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, false, true), $atts);
                     break;
                 case 'line_subtotal_tax_incl':
                     $data[$item_counter][] = $this->wcj_price_shortcode($the_order->get_line_subtotal($item, true, true), $atts);
                     break;
                 case 'line_tax':
                     $line_tax = $the_order->get_line_tax($item);
                     $line_tax = apply_filters('wcj_line_tax', $line_tax, $the_order);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_tax, $atts);
                     break;
                 case 'line_subtax':
                     $line_subtax = $the_order->get_line_subtotal($item, true, false) - $the_order->get_line_subtotal($item, false, false);
                     $data[$item_counter][] = $this->wcj_price_shortcode($line_subtax, $atts);
                     break;
                 case 'item_tax_percent':
                 case 'line_tax_percent':
                     $item_total = $the_order->get_item_total($item, false, false);
                     $item_tax_percent = 0 != $item_total ? $the_order->get_item_tax($item, false) / $item_total * 100 : 0;
                     $item_tax_percent = apply_filters('wcj_line_tax_percent', $item_tax_percent, $the_order);
                     $data[$item_counter][] = sprintf($atts['tax_percent_format'], $item_tax_percent);
                     /* $tax_labels = array();
                     			foreach ( $the_order->get_taxes() as $the_tax ) {
                     				$tax_labels[] = $the_tax['label'];
                     			}
                     			$data[ $item_counter ][] = implode( ', ', $tax_labels ); */
                     break;
                     /* case 'line_tax_percent':
                     			$line_total = $the_order->get_line_total( $item, false, true );
                     			$line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0;
                     			$line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order );
                     			$data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent );
                     			break; */
                 /* case 'line_tax_percent':
                 			$line_total = $the_order->get_line_total( $item, false, true );
                 			$line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0;
                 			$line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order );
                 			$data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent );
                 			break; */
                 default:
                     $data[$item_counter][] = '';
             }
         }
     }
     $html = wcj_get_table_html($data, array('table_class' => $atts['table_class'], 'table_heading_type' => 'horizontal', 'columns_classes' => array(), 'columns_styles' => $columns_styles));
     return $html;
 }
 /**
  * wcj_product_wholesale_price_table.
  *
  * @version 2.5.7
  */
 function wcj_product_wholesale_price_table($atts)
 {
     if (!wcj_is_product_wholesale_enabled($this->the_product->id)) {
         return '';
     }
     // Check for user role options
     $role_option_name_addon = '';
     $user_roles = get_option('wcj_wholesale_price_by_user_role_roles', '');
     if (!empty($user_roles)) {
         $current_user_role = wcj_get_current_user_first_role();
         foreach ($user_roles as $user_role_key) {
             if ($current_user_role === $user_role_key) {
                 $role_option_name_addon = '_' . $user_role_key;
                 break;
             }
         }
     }
     $wholesale_price_levels = array();
     if (wcj_is_product_wholesale_enabled_per_product($this->the_product->id)) {
         for ($i = 1; $i <= apply_filters('booster_get_option', 1, get_post_meta($this->the_product->id, '_' . 'wcj_wholesale_price_levels_number' . $role_option_name_addon, true)); $i++) {
             $level_qty = get_post_meta($this->the_product->id, '_' . 'wcj_wholesale_price_level_min_qty' . $role_option_name_addon . '_' . $i, true);
             $discount = get_post_meta($this->the_product->id, '_' . 'wcj_wholesale_price_level_discount' . $role_option_name_addon . '_' . $i, true);
             $wholesale_price_levels[] = array('quantity' => $level_qty, 'discount' => $discount);
         }
     } else {
         for ($i = 1; $i <= apply_filters('booster_get_option', 1, get_option('wcj_wholesale_price_levels_number' . $role_option_name_addon, 1)); $i++) {
             $level_qty = get_option('wcj_wholesale_price_level_min_qty' . $role_option_name_addon . '_' . $i, PHP_INT_MAX);
             $discount = get_option('wcj_wholesale_price_level_discount_percent' . $role_option_name_addon . '_' . $i, 0);
             $wholesale_price_levels[] = array('quantity' => $level_qty, 'discount' => $discount);
         }
     }
     $discount_type = wcj_is_product_wholesale_enabled_per_product($this->the_product->id) ? get_post_meta($this->the_product->id, '_' . 'wcj_wholesale_price_discount_type', true) : get_option('wcj_wholesale_price_discount_type', 'percent');
     $data_qty = array();
     $data_price = array();
     $data_discount = array();
     $columns_styles = array();
     $i = -1;
     foreach ($wholesale_price_levels as $wholesale_price_level) {
         $i++;
         if (0 == $wholesale_price_level['quantity'] && 'yes' === $atts['hide_if_zero_quantity']) {
             continue;
         }
         $the_price = '';
         if ($this->the_product->is_type('variable')) {
             // Variable
             $prices = $this->the_product->get_variation_prices(false);
             $min_key = key($prices['price']);
             end($prices['price']);
             $max_key = key($prices['price']);
             $min_product = wc_get_product($min_key);
             $max_product = wc_get_product($max_key);
             $get_price_method = 'get_price_' . get_option('woocommerce_tax_display_shop') . 'uding_tax';
             $min = $min_product->{$get_price_method}();
             $max = $max_product->{$get_price_method}();
             $min_original = $min;
             $max_original = $max;
             if ('fixed' === $discount_type) {
                 $min = $min - $wholesale_price_level['discount'];
                 $max = $max - $wholesale_price_level['discount'];
             } else {
                 $coefficient = 1.0 - $wholesale_price_level['discount'] / 100.0;
                 $min = $min * $coefficient;
                 $max = $max * $coefficient;
             }
             if ('yes' !== $atts['hide_currency']) {
                 $min = wc_price($min);
                 $max = wc_price($max);
                 $min_original = wc_price($min_original);
                 $max_original = wc_price($max_original);
             }
             $the_price = $min != $max ? sprintf('%s-%s', $min, $max) : $min;
             $the_price_original = $min_original != $max_original ? sprintf('%s-%s', $min_original, $max_original) : $min_original;
         } else {
             // Simple etc.
             $get_price_method = 'get_price_' . get_option('woocommerce_tax_display_shop') . 'uding_tax';
             $the_price = $this->the_product->{$get_price_method}();
             $the_price = apply_filters('wcj_product_wholesale_price_table_price_before', $the_price, $this->the_product);
             $the_price_original = $the_price;
             if ('price_directly' === $discount_type) {
                 $the_price = $wholesale_price_level['discount'];
             } elseif ('fixed' === $discount_type) {
                 $the_price = $the_price - $wholesale_price_level['discount'];
             } else {
                 // 'percent'
                 $coefficient = 1.0 - $wholesale_price_level['discount'] / 100.0;
                 $the_price = $the_price * $coefficient;
             }
             $the_price_original = apply_filters('wcj_product_wholesale_price_table_price_after', $the_price_original, $this->the_product);
             $the_price = apply_filters('wcj_product_wholesale_price_table_price_after', $the_price, $this->the_product);
             if ('yes' !== $atts['hide_currency']) {
                 $the_price = wc_price($the_price);
                 $the_price_original = wc_price($the_price_original);
             }
         }
         $level_max_qty = isset($wholesale_price_levels[$i + 1]['quantity']) ? $atts['before_level_max_qty'] . ($wholesale_price_levels[$i + 1]['quantity'] - 1) : $atts['last_level_max_qty'];
         $data_qty[] = str_replace(array('%level_qty%', '%level_min_qty%', '%level_max_qty%'), array($wholesale_price_level['quantity'], $wholesale_price_level['quantity'], $level_max_qty), $atts['heading_format']);
         if ('yes' === $atts['add_price_row']) {
             $data_price[] = str_replace(array('%old_price%', '%price%'), array($the_price_original, $the_price), $atts['price_row_format']);
         }
         if ('yes' === $atts['add_percent_row']) {
             if ('percent' === $discount_type) {
                 $data_discount[] = '-' . $wholesale_price_level['discount'] . '%';
             } else {
                 // 'fixed' or 'price_directly'
                 // todo (maybe)
             }
         }
         if ('yes' === $atts['add_discount_row']) {
             if ('fixed' === $discount_type) {
                 $data_discount[] = '-' . wc_price($wholesale_price_level['discount']);
             } else {
                 // 'percent' or 'price_directly'
                 // todo (maybe)
             }
         }
         $columns_styles[] = 'text-align: center;';
     }
     $table_rows = array($data_qty);
     if ('yes' === $atts['add_price_row']) {
         $table_rows[] = $data_price;
     }
     if ('yes' === $atts['add_percent_row']) {
         $table_rows[] = $data_discount;
     }
     if ('vertical' === $atts['table_format']) {
         $table_rows_modified = array();
         foreach ($table_rows as $row_number => $table_row) {
             foreach ($table_row as $column_number => $cell) {
                 $table_rows_modified[$column_number][$row_number] = $cell;
             }
         }
         $table_rows = $table_rows_modified;
     }
     return wcj_get_table_html($table_rows, array('table_class' => 'wcj_product_wholesale_price_table', 'columns_styles' => $columns_styles, 'table_heading_type' => $atts['table_format']));
 }