【问题标题】:Add text before the price在价格前添加文字
【发布时间】:2012-11-19 13:57:12
【问题描述】:

几天来,我一直在尝试在 woo commerce 单品页面内的产品价格之前添加“价格”。我已经尝试了此代码的许多变体,但均无济于事。

   /** Add "Price" before the price */
function price_text() {

?>

<div class="price-text">
<p>Price</p>
</div>

<?php

} 
add_filter('woocommerce_get_price','price_text');

这是我得到的最接近的,但它显示价格为 0 美元。

我也开始添加这段代码

'<span class="amount">' . $currency_symbol . $price . '</span>' 

无济于事。但是

总的来说,我对 PHP 和 OPP 非常陌生。任何帮助将不胜感激。

如果有影响的话,我正在使用 Genesis 框架。

【问题讨论】:

    标签: woocommerce


    【解决方案1】:

    可翻译的一点改进。

    /** Add "Price" before the price */
    add_filter('woocommerce_get_price','price_text');
    
    function price_text($price) {
      if ( is_woocommerce()){ ?>
    <div class="price-text">
      <p><?php _e('Price','woothemes'); ?></p>
    </div>
    <?php
     return $price;
     } 
    else {
            return $price;
        }
    }
    

    【讨论】:

    • 我看不出这有什么改进?
    【解决方案2】:

    耶!

    我想通了!

    add_filter('woocommerce_get_price','price_text');
    function price_text($price) {
    
    ?>
    
    <div class="price-text">
    <p>Price</p>
    </div>
    
    <?php
    
    return $price;
    
    } 
    

    我只是缺少变量

    $price

    函数声明时

    price_text

    return $price;
    

    希望这对某人有所帮助:)

    干杯, 迈克

    【讨论】:

      【解决方案3】:

      我添加了一个 if else 语句,以便它只显示在产品页面而不是结帐页面上。

      /** Add "Price" before the price */
      add_filter('woocommerce_get_price','price_text');
      function price_text($price) {
          if ( is_woocommerce()){
      ?>
      
      <div class="price-text">
      <p>Price</p>
      </div>
      <?php
      
      return $price;
      
      } 
      else {
              return $price;
          }
      }
      

      干杯, 迈克

      【讨论】:

        猜你喜欢
        • 2014-05-04
        • 1970-01-01
        • 1970-01-01
        • 2018-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-11
        相关资源
        最近更新 更多