wordpress/woocommerce:如果为零则删除价格

Ili*_*ued 3 php wordpress woocommerce

我正忙于一个 wordpress/woocommerce 网站,我想在产品类别/存档页面上隐藏零时商品的价格。

我试过在网上和 php 文件中查找,但找不到应该添加 if 语句的位置。

我的 php 知识非常有限。我想知道其他人是否有这方面的经验或可以以正确的方式帮助我

谢谢!

Koo*_*Pal 10

此代码适用于 Woocommerce 3.6.3。复制到你的functions.php

//Hide Price when Price is Zero
add_filter( 'woocommerce_get_price_html','maybe_hide_price',10,2);
function maybe_hide_price($price_html, $product){
     if($product->get_price()>0){
          return $price_html;
     }
     return '';
 } 
// End of above code
Run Code Online (Sandbox Code Playgroud)


Cra*_*key 5

这是另一种方法:

add_filter( 'woocommerce_get_price_html','maybe_hide_price',10,2);
function maybe_hide_price($price_html, $product){
     if($product->get_price()>0){
          return $price_html;
     }
     return '';
 }
Run Code Online (Sandbox Code Playgroud)