我使用一个自定义代码来修改我的价格后缀,所以我不会通过woocommerce设置来显示它,而是在我的function.php中使用这个代码来获得产品页面上的价格后缀。
function change_product_price_html($price){
$newPrice .= $price;
$newPrice .= " <span class=\"woocommerce-price-suffix\">inkl. MwSt., <a href='https://www.amaoni.de/zahlung-versand#versandkosten'>zzgl. Versandkosten</a></span>";
return $newPrice;
}但现在它也在类别页面上显示了价格后缀。
我找到了这个解决方案,但对我没有用。
add_filter('woocommerce_get_price_html', 'hide_price_on_shop');
function hide_price_on_shop($price){
if(is_shop()){
$price = '';
}
return $price;
}是否有一种方法只在产品页上有价格后缀,而在类别页上没有?

发布于 2019-02-22 19:05:00
假设您只想在产品页面上显示这一点,您可以在主题中覆盖woocommerce/single/ page e.php文件。
要做到这一点,只需将plugins/woocommerce/templates/single-product/price.php复制到yourtheme/woocommerce/single-product/price.php.
然后,在新的price.php文件中,您可以得到如下内容:
price.php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
?>
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) );?>">
<?php echo $product->get_price_html(); ?>
<span class=\"woocommerce-price-suffix\">inkl. MwSt., <a href='https://www.amaoni.de/zahlung-versand#versandkosten'>zzgl. Versandkosten</a></span>
</p>https://stackoverflow.com/questions/54831405
复制相似问题