- Trạng thái
- Đang mở
- Được báo cáo cho
- WPML Multilingual & Multicurrency for WooCommerce 5.3.2
- Thẻ chủ đề
- Bug
Tổng quan về lỗi
Widget Bảng điều khiển trạng thái WooCommerce có thể hiển thị số lượng không chính xác cho các sản phẩm sắp hết hàng. Vấn đề này phát sinh khi các sản phẩm được dịch, vì widget tính các bản dịch của một sản phẩm là các mục riêng biệt.
Giải pháp tạm thời
Vui lòng đảm bảo bạn có bản sao lưu toàn bộ trang web của mình trước khi tiếp tục.
- Mở tệp functions.php trong giao diện của bạn.
- Thêm đoạn mã sau:
add_filter( 'woocommerce_status_widget_low_in_stock_count_pre_query', 'filter_counts' ); function filter_counts( $var ){ global $wpdb; $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); $nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); $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 INNER JOIN {$wpdb->prefix}icl_translations as translations ON posts.ID=translations.element_id WHERE stock_quantity <= %d AND stock_quantity > %d AND posts.post_status = 'publish' AND translations.source_language_code IS NULL", $stock, $nostock ) ); return $lowinstock_count; }