问题
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