Hello WoodMart Support,
We have found a reproducible bug in WoodMart 8.5.0 when the Sold Counter uses real sales data together with WooCommerce HPOS.
Environment:
WoodMart 8.5.0
PHP 8.1.34, 64-bit
WooCommerce HPOS enabled
Sold counter data source: Real data
Timeframe: 3 months
The problem is located in:
wp-content/themes/woodmart/inc/integrations/woocommerce/modules/sold-counter/class-main.php
In get_average_count_for_hpos(), the SQL query joins the wc_orders table and checks:
AND o.status IN (‘wc-completed’, ‘wc-processing’)
However, it does not restrict the order type to normal orders. Consequently, completed records with:
o.type = ‘shop_order_refund’
are also included.
Refund line items contain _qty = -1. The query converts quantities using:
CAST(… AS UNSIGNED)
In MySQL:
CAST(-1 AS UNSIGNED) = 18446744073709551615
After the result is cast to a PHP integer, the Sold Counter displays:
9223372036854775807
https://snipboard.io/2SGsKf.jpg
This is PHP_INT_MAX on a 64-bit installation.
The legacy-orders implementation already avoids this problem because its query contains:
AND p.post_type = ‘shop_order’
The equivalent condition appears to be missing from the HPOS query. Adding the following condition resolves the problem:
AND o.type = ‘shop_order’
Reproduction steps:
Enable HPOS and WoodMart Sold Counter with real sales data.
Purchase a product and complete the order.
Create a refund containing a negative product quantity.
Ensure the refund record has status wc-completed.
Clear the woodmart_product_sales_{product_id} transient.
Open the product page.
Expected result:
Only quantities from normal processing or completed shop orders are counted.
Actual result:
Refund quantities are cast as unsigned values, causing the counter to display PHP_INT_MAX.
Could you please confirm this issue and whether it has already been fixed in WoodMart 8.6 or a later release?
Kind regards,
Joel Mellin
Mellins