Fatal error: Call to a member function get_price_html() on a non-object

自古美人都是妖i 提交于 2019-11-27 08:23:22

问题


I am trying to display the price of each product in the search it works for most products but when I search for a piticular product I keep getting this error

Fatal error: Call to a member function getpricehtml() on a non-object in /home/public_html/wp-content/theme/search.php on line 76

this is the only search I get the error on "CUP0501-001 2822505 Jacobsen Reel Motor WMSM4".

Here is the line on the search page that is giving me trouble

getpricehtml(); ?>

Any help would be appreciated.


回答1:


In this file $product is not define so define it.

This code might be solve your problem.

global $woocommerce;
$product = new WC_Product(get_the_ID()); 
echo $product->get_price_html(); //Shows the price


来源:https://stackoverflow.com/questions/28486911/fatal-error-call-to-a-member-function-get-price-html-on-a-non-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!