WC_Admin_Dashboard::status_widget_stock_rows() │ private │ WC 1.0
Show stock data is status widget.
Метод класса: WC_Admin_Dashboard{}
Возвращает
null
. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса
$result = $this->status_widget_stock_rows( $is_wc_admin_disabled );
- $is_wc_admin_disabled(true|false) (обязательный)
- if woocommerce admin is disabled.
Код WC_Admin_Dashboard::status_widget_stock_rows() WC Admin Dashboard::status widget stock rows
WC 8.3.1
<?php
private function status_widget_stock_rows( $is_wc_admin_disabled ) {
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_link = 'admin.php?page=wc-reports&tab=stock&report=low_in_stock';
$outofstock_link = 'admin.php?page=wc-reports&tab=stock&report=out_of_stock';
if ( false === $is_wc_admin_disabled ) {
$lowstock_link = 'admin.php?page=wc-admin&type=lowstock&path=%2Fanalytics%2Fstock';
$outofstock_link = 'admin.php?page=wc-admin&type=outofstock&path=%2Fanalytics%2Fstock';
}
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( $lowstock_link ) ); ?>">
<?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( $outofstock_link ) ); ?>">
<?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
}