class-wc-admin-report.php
1 year ago
class-wc-report-coupon-usage.php
5 years ago
class-wc-report-customer-list.php
9 months ago
class-wc-report-customers.php
9 months ago
class-wc-report-downloads.php
5 years ago
class-wc-report-low-in-stock.php
5 years ago
class-wc-report-most-stocked.php
5 years ago
class-wc-report-out-of-stock.php
5 years ago
class-wc-report-sales-by-category.php
2 years ago
class-wc-report-sales-by-date.php
1 year ago
class-wc-report-sales-by-product.php
3 months ago
class-wc-report-stock.php
1 year ago
class-wc-report-taxes-by-code.php
1 year ago
class-wc-report-taxes-by-date.php
1 year ago
class-wc-report-stock.php
208 lines
| 1 | <?php |
| 2 | |
| 3 | use Automattic\WooCommerce\Enums\ProductType; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; // Exit if accessed directly |
| 7 | } |
| 8 | |
| 9 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 10 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * WC_Report_Stock. |
| 15 | * |
| 16 | * @author WooThemes |
| 17 | * @category Admin |
| 18 | * @package WooCommerce\Admin\Reports |
| 19 | * @version 2.1.0 |
| 20 | */ |
| 21 | class WC_Report_Stock extends WP_List_Table { |
| 22 | |
| 23 | /** |
| 24 | * Max items. |
| 25 | * |
| 26 | * @var int |
| 27 | */ |
| 28 | protected $max_items; |
| 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | */ |
| 33 | public function __construct() { |
| 34 | |
| 35 | parent::__construct( |
| 36 | array( |
| 37 | 'singular' => 'stock', |
| 38 | 'plural' => 'stock', |
| 39 | 'ajax' => false, |
| 40 | ) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * No items found text. |
| 46 | */ |
| 47 | public function no_items() { |
| 48 | _e( 'No products found.', 'woocommerce' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Don't need this. |
| 53 | * |
| 54 | * @param string $position |
| 55 | */ |
| 56 | public function display_tablenav( $position ) { |
| 57 | |
| 58 | if ( 'top' !== $position ) { |
| 59 | parent::display_tablenav( $position ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Output the report. |
| 65 | */ |
| 66 | public function output_report() { |
| 67 | |
| 68 | $this->prepare_items(); |
| 69 | echo '<div id="poststuff" class="woocommerce-reports-wide">'; |
| 70 | $this->display(); |
| 71 | echo '</div>'; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get column value. |
| 76 | * |
| 77 | * @param mixed $item |
| 78 | * @param string $column_name |
| 79 | */ |
| 80 | public function column_default( $item, $column_name ) { |
| 81 | global $product; |
| 82 | |
| 83 | if ( ! $product || $product->get_id() !== $item->id ) { |
| 84 | $product = wc_get_product( $item->id ); |
| 85 | } |
| 86 | |
| 87 | if ( ! $product ) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | switch ( $column_name ) { |
| 92 | |
| 93 | case 'product': |
| 94 | if ( $sku = $product->get_sku() ) { |
| 95 | echo esc_html( $sku ) . ' - '; |
| 96 | } |
| 97 | |
| 98 | echo esc_html( $product->get_name() ); |
| 99 | |
| 100 | // Get variation data. |
| 101 | if ( $product->is_type( ProductType::VARIATION ) ) { |
| 102 | echo '<div class="description">' . wp_kses_post( wc_get_formatted_variation( $product, true ) ) . '</div>'; |
| 103 | } |
| 104 | break; |
| 105 | |
| 106 | case 'parent': |
| 107 | if ( $item->parent ) { |
| 108 | echo esc_html( get_the_title( $item->parent ) ); |
| 109 | } else { |
| 110 | echo '-'; |
| 111 | } |
| 112 | break; |
| 113 | |
| 114 | case 'stock_status': |
| 115 | if ( $product->is_on_backorder() ) { |
| 116 | $stock_html = '<mark class="onbackorder">' . __( 'On backorder', 'woocommerce' ) . '</mark>'; |
| 117 | } elseif ( $product->is_in_stock() ) { |
| 118 | $stock_html = '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>'; |
| 119 | } else { |
| 120 | $stock_html = '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>'; |
| 121 | } |
| 122 | echo apply_filters( 'woocommerce_admin_stock_html', $stock_html, $product ); |
| 123 | break; |
| 124 | |
| 125 | case 'stock_level': |
| 126 | echo esc_html( $product->get_stock_quantity() ); |
| 127 | break; |
| 128 | |
| 129 | case 'wc_actions': |
| 130 | ?><p> |
| 131 | <?php |
| 132 | $actions = array(); |
| 133 | $action_id = $product->is_type( ProductType::VARIATION ) ? $item->parent : $item->id; |
| 134 | |
| 135 | $actions['edit'] = array( |
| 136 | 'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ), |
| 137 | 'name' => __( 'Edit', 'woocommerce' ), |
| 138 | 'action' => 'edit', |
| 139 | ); |
| 140 | |
| 141 | if ( $product->is_visible() ) { |
| 142 | $actions['view'] = array( |
| 143 | 'url' => get_permalink( $action_id ), |
| 144 | 'name' => __( 'View', 'woocommerce' ), |
| 145 | 'action' => 'view', |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | $actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product ); |
| 150 | |
| 151 | foreach ( $actions as $action ) { |
| 152 | printf( |
| 153 | '<a class="button tips %1$s" href="%2$s" data-tip="%3$s">%4$s</a>', |
| 154 | esc_attr( $action['action'] ), |
| 155 | esc_url( $action['url'] ), |
| 156 | sprintf( esc_attr__( '%s product', 'woocommerce' ), $action['name'] ), |
| 157 | esc_html( $action['name'] ) |
| 158 | ); |
| 159 | } |
| 160 | ?> |
| 161 | </p> |
| 162 | <?php |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Get columns. |
| 169 | * |
| 170 | * @return array |
| 171 | */ |
| 172 | public function get_columns() { |
| 173 | |
| 174 | $columns = array( |
| 175 | 'product' => __( 'Product', 'woocommerce' ), |
| 176 | 'parent' => __( 'Parent', 'woocommerce' ), |
| 177 | 'stock_level' => __( 'Units in stock', 'woocommerce' ), |
| 178 | 'stock_status' => __( 'Stock status', 'woocommerce' ), |
| 179 | 'wc_actions' => __( 'Actions', 'woocommerce' ), |
| 180 | ); |
| 181 | |
| 182 | return $columns; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Prepare customer list items. |
| 187 | */ |
| 188 | public function prepare_items() { |
| 189 | |
| 190 | $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); |
| 191 | $current_page = absint( $this->get_pagenum() ); |
| 192 | $per_page = apply_filters( 'woocommerce_admin_stock_report_products_per_page', 20 ); |
| 193 | |
| 194 | $this->get_items( $current_page, $per_page ); |
| 195 | |
| 196 | /** |
| 197 | * Pagination. |
| 198 | */ |
| 199 | $this->set_pagination_args( |
| 200 | array( |
| 201 | 'total_items' => $this->max_items, |
| 202 | 'per_page' => $per_page, |
| 203 | 'total_pages' => ceil( $this->max_items / $per_page ), |
| 204 | ) |
| 205 | ); |
| 206 | } |
| 207 | } |
| 208 |