Php 如何向div添加函数

Php 如何向div添加函数,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图添加一个函数,该函数将显示一个产品的价格略低于销售徽章,但我有麻烦的代码。。它在前端工作正常,但wordpress发现它错了,并在后端显示错误(当我打开插件设置时) 添加此项的正确方法是什么 Fatal error: Uncaught Error: Call to a member function get_price_html() on null in /wp-content/plugins/yith-woocommerce-badge-management-premium/templa

我试图添加一个函数,该函数将显示一个产品的价格略低于销售徽章,但我有麻烦的代码。。它在前端工作正常,但wordpress发现它错了,并在后端显示错误(当我打开插件设置时)

添加此项的正确方法是什么

Fatal error: Uncaught Error: Call to a member function get_price_html() on null in /wp-content/plugins/yith-woocommerce-badge-management-premium/templates/badge_content_premium.php:36 Stack trace: #0 
/wp-content/plugins/yith-woocommerce-badge-management-premium/functions.yith-wcbm.php(205): include() #1 
/wp-content/plugins/yith-woocommerce-badge-management-premium/functions.yith-wcbm-premium.php(807): yith_wcbm_get_template('badge_content_p...', Array) #2 
/wp-content/plugins/yith-woocommerce-badge-management-premium/class.yith-wcbm-admin-premium.php(109): yith_wcbm_get_badge_premium(364, 'preview') #3 
/wp-includes/class-wp-hook.php(286): YITH_WCBM_Admin_Premium->badge_custom_columns('yith_wcbm_previ...' in 
/wp-content/plugins/yith-woocommerce-badge-management-premium/templates/badge_content_premium.php on line 36
这是我在第36行添加的代码

<div class='<?php echo $badge_classes ?> yith-wcbm-badge-custom' <?php echo $position_data_html ?>>

            <div class='yith-wcbm-badge__wrap'>
                <div class="yith-wcbm-badge-text"><b><?php echo $text ?>
LINE 36-      <div class="roundedborder"><?php echo $product->get_price_html(); ?></b></div></div>
            </div><!--yith-wcbm-badge__wrap-->
        </div><!--yith-wcbm-badge-->
>
第36行-

我试图定义$product,显然我做错了什么,我也尝试了
global$woodcommerce$product=新的WC_产品(获取_ID())它们都不能解决问题

似乎对象$product不存在。 以下是同样的问题,可能对您有所帮助:



生成此错误是因为您的$product为空,请尝试获取product对象,而不是获取价格

谢谢您的建议,我已经尝试过了,错误现在更改为提示异常:无效产品。在/wp content/plugins/woocommerce/includes/data stores/class wc product data store cpt.php:163堆栈跟踪:#0/wp content/plugins/woocommerce/includes/class wc data store.php(159):wc_product_data_store_cpt->read(Object(wc_product))#1/wp content/plugins/woocommerce/includests/abstracts/abstract wc product.php(135):wc_data_store->->read(Object(WC#u Product)#2/wp content/plugins/yith woocommerce徽章管理高级/模板/badge#u content#u premium.php(29):WC#u Product->uu构造(364)#3/wp content/plugins/yith woocommerce徽章管理高级/函数。yith wcbm.php(205):包括('/homepages/13/d.)#4/homepages/13/d767788347/htdocs/clickand in/wp content/plugins/woocmerce/includes/data stores/class-wc-product-data-store-cpt.php第163行创建产品对象时遇到问题,请尝试检查函数是否获取_ID()检索正确的产品ID,如果没有,请确保将产品ID发送到此页面,0已解决!!
global$woocommerce;$product=new WC\u product($product\u ID);echo$product->get\u price\u html();
对我来说需要4天时间……希望下一位阅读者喜欢:)我试图将全局$product放在规则的顶部,但仍然收到错误消息:/我试图定义
$product
,显然我做错了什么,我也尝试了
全局$product$product=新的WC_产品(获取_ID())它们都不能解决问题
<?php
    global $woocommerce;
    $product = new WC_Product(get_the_ID()); 
    echo $product->get_price_html(); //Shows the price
?>