致命错误:在非对象上调用成员函数 get_price_html() [英] Fatal error: Call to a member function get_price_html() on a non-object
问题描述
我试图在搜索中显示每种产品的价格,它适用于大多数产品,但是当我搜索一种垂体产品时,我不断收到此错误
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
致命错误:在第 76 行的/home/public_html/wp-content/theme/search.php 中的非对象上调用成员函数 getpricehtml()
Fatal error: Call to a member function getpricehtml() on a non-object in /home/public_html/wp-content/theme/search.php on line 76
这是我在CUP0501-001 2822505 Jacobsen Reel Motor WMSM4"上遇到错误的唯一搜索.
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
任何帮助将不胜感激.
推荐答案
在这个文件中 $product
没有定义,所以定义它.
In this file $product
is not defined, so define it.
此代码可能会解决您的问题.
This code might solve your problem.
global $woocommerce;
$product = new WC_Product(get_the_ID());
echo $product->get_price_html(); //Shows the price
这篇关于致命错误:在非对象上调用成员函数 get_price_html()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!