/**
  * Output custom columns for orders
  *
  * @param   string $column
  * @version 2.2.6
  * @since   2.2.4
  */
 public function render_order_columns($column)
 {
     if ('profit' === $column) {
         $total_profit = 0;
         $the_order = wc_get_order(get_the_ID());
         if ('completed' === $the_order->get_status()) {
             $is_forecasted = false;
             foreach ($the_order->get_items() as $item_id => $item) {
                 //					$product = $this->get_product_from_item( $item );
                 $the_profit = 0;
                 if (0 != ($purchase_price = wc_get_product_purchase_price($item['product_id']))) {
                     $the_profit = $item['line_total'] + $item['line_tax'] - $purchase_price * $item['qty'];
                     //						$total_profit += $the_profit;
                     //						echo $item['line_total'] . ' ~ ' . $purchase_price . ' ~ ' . $item['qty'];
                 } else {
                     //$the_profit = ( $item['line_total'] + $item['line_tax'] ) * 0.2;
                     $is_forecasted = true;
                 }
                 $total_profit += $the_profit;
             }
         }
         if (0 != $total_profit) {
             if (!$is_forecasted) {
                 echo '<span style="color:green;">';
             }
             echo wc_price($total_profit);
             if (!$is_forecasted) {
                 echo '</span>';
             }
         }
     }
 }
 public function gather_products_data(&$products_info)
 {
     //return array();
     $args = array('post_type' => 'product', 'posts_per_page' => -1);
     $loop = new WP_Query($args);
     if ($loop->have_posts()) {
         while ($loop->have_posts()) {
             $loop->the_post();
             $the_ID = get_the_ID();
             //$the_product = new WC_Product( $the_ID );
             $the_product = wc_get_product($the_ID);
             $the_price = $the_product->get_price();
             $the_stock = $the_product->get_total_stock();
             //if ( 0 == $the_stock )
             //$the_stock = get_post_meta( $the_ID, '_stock', true );
             $the_title = get_the_title();
             $the_categories = $the_product->get_categories();
             $the_date = get_the_date();
             $the_permalink = get_the_permalink();
             $post_custom = get_post_custom($the_ID);
             $total_sales = isset($post_custom['total_sales'][0]) ? $post_custom['total_sales'][0] : 0;
             //$available_variations = $the_product->get_available_variations();
             $purchase_price = wc_get_product_purchase_price($the_ID);
             $sales_in_day_range = array();
             foreach ($this->ranges_in_days as $the_range) {
                 $sales_in_day_range[$the_range] = 0;
             }
             $products_info[$the_ID] = array('ID' => $the_ID, 'title' => $the_title, 'category' => $the_categories, 'permalink' => $the_permalink, 'price' => $the_price, 'stock' => $the_stock, 'stock_price' => $the_price * $the_stock, 'total_sales' => $total_sales, 'date_added' => $the_date, 'purchase_price' => $purchase_price, 'last_sale' => 0, 'sales_in_period' => $sales_in_day_range);
         }
     }
 }
 /**
  * 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;
             }
         }
     }
 }
 /**
  * wcj_product_purchase_price.
  *
  * @return string
  */
 function wcj_product_purchase_price($atts)
 {
     $purchase_price = wc_get_product_purchase_price($the_product->id);
     return wc_price($purchase_price);
 }
 /**
  * wcj_product_purchase_price.
  *
  * @return string
  */
 function wcj_product_purchase_price($atts)
 {
     $purchase_price = wc_get_product_purchase_price($the_product->id);
     return wc_price($purchase_price);
     //return get_post_meta( $the_product->id, '_' . 'wcj_purchase_price', true );
 }