Timber: Woocommerce Uncaught Error Call to a member function is_on_sale()

Created on 4 May 2017  路  4Comments  路  Source: timber/timber

Is this a support or usage question? Please post to StackOverflow using the Timber tag

Expected behavior


No Error

Actual behavior


returns this error message

Fatal error: Uncaught Error: Call to a member function is_on_sale() on boolean in /Users/jake/code/theme/public/content/plugins/woocommerce/templates/loop/sale-flash.php:26 Stack trace: #0 /Users/jake/code/theme/public/content/plugins/woocommerce/includes/wc-core-functions.php(204): include() #1 /Users/jake/code/theme/public/content/plugins/woocommerce/includes/wc-template-functions.php(737): wc_get_template('loop/sale-flash...') #2 /Users/jake/code/theme/public/wp/wp-includes/class-wp-hook.php(298): woocommerce_show_product_loop_sale_flash(Array) #3 /Users/jake/code/theme/public/wp/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array) #4 /Users/jake/code/theme/public/wp/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #5 [internal function]: do_action('woocommerce_bef...', Array) #6 /Users/jake/code/theme/vendor/timber/timber/lib/Twig.php(82): call_user_func_array('do_action', Array) #7 /Users/jake/code/theme/vendor/twig/twig/lib/Twig/Environment.php(462) : ev in /Users/jake/code/theme/public/content/plugins/woocommerce/templates/loop/sale-flash.php on line 26

Steps to reproduce behavior

What version of WordPress, PHP and Timber are you using?


Latest WordPress / PHP 7.1 / Timber 1.3.0 / Woocommerce 3.0.5

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)


Composer/Packagist

Most helpful comment

Fixed: added {{ fn('timber_set_product', post) }} to single-product.twig. This seems to be missing from the docs (https://github.com/timber/timber/blob/master/docs/guides/woocommerce.md)

All 4 comments

Hello
@JakeHenshall
kindly inform me if you got the solution to the above issue, if so, kindly assist, as i have the same issue
Best Regards
Steve

@ndungu4st @JakeHenshall Were either of you able to fix this?

It's funny because I built another site with Timber and Woocommerce and I don't have this error showing up.

Fixed: added {{ fn('timber_set_product', post) }} to single-product.twig. This seems to be missing from the docs (https://github.com/timber/timber/blob/master/docs/guides/woocommerce.md)

@geoffyuen how were you able to call the function? If I place it inside my functions.php it outputs the following:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'timber_set_product' not found or invalid function name in /Users/enrico/Arbeit/Friendventure/Projekte/Friendation/wp-friendation/web/app/themes/friendation/vendor/timber/timber/lib/Twig.php on line 302

Was this page helpful?
0 / 5 - 0 ratings