I created a simple e-commerce website and uploaded around 100 products (all of them are Simple-Products). Initially, I had no problems, but after uploading about 60 products, I started receiving this error. Here is the error I am encountering:
Warning: Attempt to read property "min_price" on null in C:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\widgets\class-wc-widget-price-filter.php on line 91
Warning: Attempt to read property "max_price" on null in C:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\widgets\class-wc-widget-price-filter.php on line 92
This is the highlighted code line, suggested by the Warning:
//89 Find min and max price in current result set.
//90 $prices = $this->get_filtered_price();
//91 $min_price = $prices->min_price;
//92 $max_price = $prices->max_price;
I checked some other answers for it and tried inserting the code from Filter products by price range using WooCommerce wc_get_products, although I do not know PHP well so I do not even know where to insert the code (I tried inserting it in functions.php in the WooCommerce Folder) but nothing worked. Some suggested updating WordPress or WooCommerce which I doubt will solve the problem unless anyone else suggests it here too. Others said that Variable-Products cause these, but I am sure that all of my products are Simple type.
The error you’re seeing suggests that WooCommerce’s Price Filter widget is trying to access price properties from a result set, but it’s encountering a null value. This can happen if there are products without pricing information or if the filter is applied to an empty result set.
Here are a few troubleshooting steps to resolve this:
1. Check if all products have prices:
Ensure that all 100 products have valid prices (i.e., not left empty or set to 0).
You can do this by editing each product in WooCommerce and verifying the price field.
2. Check for database inconsistencies:
It’s possible that some database entries were incomplete or corrupted when uploading products. You can try re-saving the product data to regenerate these values:
Go to the WooCommerce dashboard.
Edit one of the products.
Save it again without making changes.
Repeat this for a few products and see if the error persists.
3. Manually adjust the widget code:
You can modify the code to check if $prices is null before accessing its properties. This should prevent the error from being triggered:
In the file wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-price-filter.php around lines 90–92, update the code to:
This ensures that if $prices is null, it won’t cause an error and the widget will still function.
4. Flush WooCommerce Transients:
Sometimes the issue might be due to cached data. To clear this:
Go to WooCommerce > Status > Tools.
Look for the option “Clear WooCommerce transients” and click it.
Also, try “Regenerate the product lookup tables.”
5. Update WooCommerce:
If you’re running an outdated version of WooCommerce, updating to the latest version might resolve the issue, as there could be bug fixes related to this.
After trying these steps, let me know if the issue persists!