skip to Main Content

I’m customising the Woocommerce content-single-product.php and want to add a custom template file for the sidebar.

so far I’ve tried:

<?php require get_stylesheet_directory() . '/layout/page-sidebar.php'; ?>

This works elsewhere in my theme but not on Woocommerce templates where it gives an error.

Fatal error: Uncaught Error: Call to a member function get_price_html() on null in /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/single-product/price.php:25 Stack trace: #0 /Applications/MAMP/htdocs/stage/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include() #1 /Applications/MAMP/htdocs/stage/wp-content/plugins/woocommerce/includes/wc-template-functions.php(1524): wc_get_template(‘single-product/…’) #2 /Applications/MAMP/htdocs/stage/wp-includes/class-wp-hook.php(288): woocommerce_template_single_price(”) #3 /Applications/MAMP/htdocs/stage/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(NULL, Array) #4 /Applications/MAMP/htdocs/stage/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #5 /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/content-single-product.php(54): do_action(‘woocommerce_sin…’) #6 /Applications/MAMP/htdocs/stage/wp-includes/template.php(724): require(‘/Applications/M…’) #7 /Applications/MAMP/htdocs/stage/ in /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/single-product/price.php on line 25

2

Answers


  1. Chosen as BEST ANSWER

    It was a query in my template file I was calling.

    <?php endwhile; wp_reset_query(); ?>

    Fixed the problem.


  2. get_price_html() has to be called on an instance of $product. Maybe there is no product on your page and thats why it is null – which is again why your error says called get_price_html() on null.

    As your’re on a product there should be a product loaded, so you can try finding the product by calling global $product; before the method is called.

    The error says that the method was called on line 25 – is this the line of the import?

    We would need some more surrounding code to really track down the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search