- This topic has 5 replies, 2 voices, and was last updated 6 months, 2 weeks ago by Tom.
July 4, 2020 at 1:17 pm #1352061david
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.July 4, 2020 at 1:59 pm #1352087TomLead DeveloperLead Developer
It seems like you’re adding a call to
get_total_stock()in the parent theme
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.July 4, 2020 at 2:03 pm #1352091david
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?July 4, 2020 at 2:08 pm #1352094TomLead DeveloperLead Developer
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.phpfile 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.July 4, 2020 at 2:10 pm #1352096david
what could have added code to the file ?
Would a plugin be able to add to it ?July 4, 2020 at 2:12 pm #1352098TomLead DeveloperLead Developer
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.phpfile, 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).
- You must be logged in to reply to this topic.