WC_Report_Stock

WC_Report_Stock.

Defined (1)

The class is defined in the following location(s).

/includes/admin/reports/class-wc-report-stock.php  
  1. class WC_Report_Stock extends WP_List_Table { 
  2.  
  3. /** 
  4. * Max items. 
  5. * @var int 
  6. */ 
  7. protected $max_items; 
  8.  
  9. /** 
  10. * Constructor. 
  11. */ 
  12. public function __construct() { 
  13.  
  14. parent::__construct( array( 
  15. 'singular' => 'stock',  
  16. 'plural' => 'stock',  
  17. 'ajax' => false,  
  18. ) ); 
  19.  
  20. /** 
  21. * No items found text. 
  22. */ 
  23. public function no_items() { 
  24. _e( 'No products found.', 'woocommerce' ); 
  25.  
  26. /** 
  27. * Don't need this. 
  28. * @param string $position 
  29. */ 
  30. public function display_tablenav( $position ) { 
  31.  
  32. if ( 'top' !== $position ) { 
  33. parent::display_tablenav( $position ); 
  34.  
  35. /** 
  36. * Output the report. 
  37. */ 
  38. public function output_report() { 
  39.  
  40. $this->prepare_items(); 
  41. echo '<div id="poststuff" class="woocommerce-reports-wide">'; 
  42. $this->display(); 
  43. echo '</div>'; 
  44.  
  45. /** 
  46. * Get column value. 
  47. * @param mixed $item 
  48. * @param string $column_name 
  49. */ 
  50. public function column_default( $item, $column_name ) { 
  51. global $product; 
  52.  
  53. if ( ! $product || $product->get_id() !== $item->id ) { 
  54. $product = wc_get_product( $item->id ); 
  55.  
  56. if ( ! $product ) { 
  57. return; 
  58.  
  59. switch ( $column_name ) { 
  60.  
  61. case 'product' : 
  62. if ( $sku = $product->get_sku() ) { 
  63. echo esc_html( $sku ) . ' - '; 
  64.  
  65. echo esc_html( $product->get_name() ); 
  66.  
  67. // Get variation data. 
  68. if ( $product->is_type( 'variation' ) ) { 
  69. echo '<div class="description">' . wp_kses_post( wc_get_formatted_variation( $product, true ) ) . '</div>'; 
  70. break; 
  71.  
  72. case 'parent' : 
  73. if ( $item->parent ) { 
  74. echo get_the_title( $item->parent ); 
  75. } else { 
  76. echo '-'; 
  77. break; 
  78.  
  79. case 'stock_status' : 
  80. if ( $product->is_in_stock() ) { 
  81. $stock_html = '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>'; 
  82. } else { 
  83. $stock_html = '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>'; 
  84. echo apply_filters( 'woocommerce_admin_stock_html', $stock_html, $product ); 
  85. break; 
  86.  
  87. case 'stock_level' : 
  88. echo esc_html( $product->get_stock_quantity() ); 
  89. break; 
  90.  
  91. case 'wc_actions' : 
  92. ?><p> 
  93. <?php 
  94. $actions = array(); 
  95. $action_id = $product->is_type( 'variation' ) ? $item->parent : $item->id; 
  96.  
  97. $actions['edit'] = array( 
  98. 'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ),  
  99. 'name' => __( 'Edit', 'woocommerce' ),  
  100. 'action' => "edit",  
  101. ); 
  102.  
  103. if ( $product->is_visible() ) { 
  104. $actions['view'] = array( 
  105. 'url' => get_permalink( $action_id ),  
  106. 'name' => __( 'View', 'woocommerce' ),  
  107. 'action' => "view",  
  108. ); 
  109.  
  110. $actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product ); 
  111.  
  112. foreach ( $actions as $action ) { 
  113. printf( 
  114. '<a class="button tips %1$s" href="%2$s" data-tip="%3$s">%4$s</a>',  
  115. esc_attr( $action['action'] ),  
  116. esc_url( $action['url'] ),  
  117. sprintf( esc_attr__( '%s product', 'woocommerce' ), $action['name'] ),  
  118. esc_html( $action['name'] ) 
  119. ); 
  120. ?> 
  121. </p><?php 
  122. break; 
  123.  
  124. /** 
  125. * Get columns. 
  126. * @return array 
  127. */ 
  128. public function get_columns() { 
  129.  
  130. $columns = array( 
  131. 'product' => __( 'Product', 'woocommerce' ),  
  132. 'parent' => __( 'Parent', 'woocommerce' ),  
  133. 'stock_level' => __( 'Units in stock', 'woocommerce' ),  
  134. 'stock_status' => __( 'Stock status', 'woocommerce' ),  
  135. 'wc_actions' => __( 'Actions', 'woocommerce' ),  
  136. ); 
  137.  
  138. return $columns; 
  139.  
  140. /** 
  141. * Prepare customer list items. 
  142. */ 
  143. public function prepare_items() { 
  144.  
  145. $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); 
  146. $current_page = absint( $this->get_pagenum() ); 
  147. $per_page = apply_filters( 'woocommerce_admin_stock_report_products_per_page', 20 ); 
  148.  
  149. $this->get_items( $current_page, $per_page ); 
  150.  
  151. /** 
  152. * Pagination. 
  153. */ 
  154. $this->set_pagination_args( array( 
  155. 'total_items' => $this->max_items,  
  156. 'per_page' => $per_page,  
  157. 'total_pages' => ceil( $this->max_items / $per_page ),  
  158. ) );