【问题标题】:hide Woocommerce price suffix on category page在类别页面上隐藏 Woocommerce 价格后缀
【发布时间】:2019-07-16 19:16:13
【问题描述】:

我正在使用自定义代码来修改我的价格后缀,所以我没有通过 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;
}

有没有办法让价格后缀只出现在产品页面而不出现在类别页面上?

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:

    假设您希望它仅在产品页面上显示,您可以覆盖主题中的 woocommerce/single-product/price.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>
    

    【讨论】:

      猜你喜欢
      • 2018-09-01
      • 2019-12-04
      • 1970-01-01
      • 2016-09-24
      • 2018-09-06
      • 2012-11-02
      • 1970-01-01
      • 2018-07-18
      • 2018-05-14
      相关资源
      最近更新 更多