Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WC_Admin_Dashboard::status_widget_stock_rows( bool $is_wc_admin_disabled )
Show stock data is status widget.
Description Description
Parameters Parameters
- $is_wc_admin_disabled
-
(Required) if woocommerce admin is disabled.
Source Source
File: includes/admin/class-wc-admin-dashboard.php
private function status_widget_stock_rows() { global $wpdb; // Requires lookup table added in 3.6. if ( version_compare( get_option( 'woocommerce_db_version', null ), '3.6', '<' ) ) { return; } $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); $nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); $transient_name = 'wc_low_stock_count'; $lowinstock_count = get_transient( $transient_name ); if ( false === $lowinstock_count ) { /** * Status widget low in stock count pre query. * * @since 4.3.0 * @param null|string $low_in_stock_count Low in stock count, by default null. * @param int $stock Low stock amount. * @param int $nostock No stock amount */ $lowinstock_count = apply_filters( 'woocommerce_status_widget_low_in_stock_count_pre_query', null, $stock, $nostock ); if ( is_null( $lowinstock_count ) ) { $lowinstock_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} AS lookup INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID WHERE stock_quantity <= %d AND stock_quantity > %d AND posts.post_status = 'publish'", $stock, $nostock ) ); } set_transient( $transient_name, (int) $lowinstock_count, DAY_IN_SECONDS * 30 ); } $transient_name = 'wc_outofstock_count'; $outofstock_count = get_transient( $transient_name ); if ( false === $outofstock_count ) { /** * Status widget out of stock count pre query. * * @since 4.3.0 * @param null|string $outofstock_count Out of stock count, by default null. * @param int $nostock No stock amount */ $outofstock_count = apply_filters( 'woocommerce_status_widget_out_of_stock_count_pre_query', null, $nostock ); if ( is_null( $outofstock_count ) ) { $outofstock_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} AS lookup INNER JOIN {$wpdb->posts} as posts ON lookup.product_id = posts.ID WHERE stock_quantity <= %d AND posts.post_status = 'publish'", $nostock ) ); } set_transient( $transient_name, (int) $outofstock_count, DAY_IN_SECONDS * 30 ); } ?> <li class="low-in-stock"> <a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-reports&tab=stock&report=low_in_stock' ) ); ?>"> <?php printf( /* translators: %s: order count */ _n( '<strong>%s product</strong> low in stock', '<strong>%s products</strong> low in stock', $lowinstock_count, 'woocommerce' ), $lowinstock_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?> </a> </li> <li class="out-of-stock"> <a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-reports&tab=stock&report=out_of_stock' ) ); ?>"> <?php printf( /* translators: %s: order count */ _n( '<strong>%s product</strong> out of stock', '<strong>%s products</strong> out of stock', $outofstock_count, 'woocommerce' ), $outofstock_count ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?> </a> </li> <?php }