WC_Admin_Dashboard::status_widget_stock_rows()
Show stock data is status widget.
Method of the class: WC_Admin_Dashboard{}
Hooks from the method
Return
null
. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->status_widget_stock_rows( $lowstock_link, $outofstock_link );
- $lowstock_link(string) (required)
- Low stock link.
- $outofstock_link(string) (required)
- Out of stock link.
WC_Admin_Dashboard::status_widget_stock_rows() WC Admin Dashboard::status widget stock rows code WC 9.7.1
<?php private function status_widget_stock_rows( $lowstock_link, $outofstock_link ) { 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 ); $lowstock_url = $lowstock_link ? admin_url( $lowstock_link ) : '#'; $outofstock_url = $outofstock_link ? admin_url( $outofstock_link ) : '#'; 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( $lowstock_url ); ?>"> <?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( $outofstock_url ); ?>"> <?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 }