Archived topic
Error when making variable product
5 replies · Started by david on July 4, 2020
I've a site with woocommerence and it's working fine. I tried to add a variable product and I got this error.. I removed my domain folder.
Fatal error: Uncaught Error: Call to a member function get_total_stock() on null in /home/**********/public_html/wp-content/themes/generatepress/functions.php:108 Stack trace: #0 /home/**********/public_html/wp-includes/class-wp-hook.php(287): custom_get_availability(Array, Object(WC_Product_Variation)) #1 /home/**********/public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters(Array, Array) #2 /home/**********/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1991): apply_filters('woocommerce_get...', Array, Object(WC_Product_Variation)) #3 /home/**********/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3401): WC_Product->get_availability() #4 /home/**********/public_html/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(339): wc_get_stock_html(Object(WC_Product_Variation)) #5 /home/**********/public_html/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(310): WC_Product_Variable->get_available_variation(Object(WC_Product_Variation)) # in /home/**********/public_html/wp-content/themes/generatepress/functions.php on line 108
I've not publish this product.. I was just testing something new I need to add. So the site is still working.. But I need to add this.
Hi there,
It seems like you're adding a call to get_total_stock() in the parent theme functions.php file.
Instead of adding anything to that file, you should use one of these methods: https://docs.generatepress.com/article/adding-php/
You'll need to either remove that function or alter it so it doesn't cause the error.
I've not edited the code at all.
I'm just trying to add a variable product. Shouldn't the theme be able to handle variable products?
Absolutely, but the error is saying:
Fatal error: Uncaught Error: Call to a member function get_total_stock() on null in /home/**********/public_html/wp-content/themes/generatepress/functions.php:108
There is no get_total_stock() function in the functions.php file on line 108. In fact, there are only 98 lines in that file: https://github.com/tomusborne/generatepress/blob/2.4.2/functions.php#L98
This means the file has been altered, and the code inside that file is causing the error. Once you remove the custom code, the issue should go away.
The file can be edited in "Appearance > Themes > Theme Editor", or you can simply update the theme or re-install it to get fresh files.
what could have added code to the file ?
Would a plugin be able to add to it ?
Not likely, unless you have a very sketchy plugin activated.
A lot of instructions out there tell you to add code to your themes functions.php file, so it's an easy thing to do without really thinking about it. It could have also been someone else you have working on your site (if there is anyone with access, of course).