duanpai1033 2013-11-12 16:51
浏览 34
已采纳

使用woocommerce为wordpress页面添加elseif语句

I've tried several different things, but with no good results. I'm attempting to add an elseif which will allow me to echo "Enquire for Price" instead of a price if left blank on a wordpress.org site that uses Woocommerce. Instead, the price is being shown as 0 or EnquireforPrice£0. Our custom theme doesn't have a price.html or loop.html file, so I can't edit those. The price.html file in single-product (woocommerce folder) shows EnquireforPrice£(whatever the original price was) when I tried to edit it with the elseif I found on this wordpress woocommerce support thread

This is my current code that doesn't allow for enquire for price and for some reason I'm drawing a blank on how to get it to work.

<?php echo ($product->get_stock_quantity() < 1) ? '<span class="sold">Sold</span>' : null; ?><?php if ($product->get_stock_quantity() != 0) : ?><p class="price"><?php echo woocommerce_price(get_post_meta(get_the_ID(), '_price', true)); ?></p><?php endif; ?>

Basically, I need it to say Enquire for price if the price is left blank in the individual product price, but if there is a price to list the price. It should be straight forward, yet for some reason it simply isn't.

Thanks for any help that can be offered!

PS I've also tried the wordpress plugins that are supposed to do this, but they only work on the product page and leave £0 on the home and search pages.

  • 写回答

1条回答 默认 最新

  • dqtok88424 2013-11-12 17:07
    关注

    I have downloaded woocommerce and have it working for me. Open

    plugins/woocommerce/templates/single-product/price.php
    

    Find this line

    <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
    

    Replace it with the code below

    <p itemprop="price" class="price">
        <?php 
            $price = $product->get_price_html();
            if(empty($price))
            {
                echo '<a href="link">Anchor Text</a>';
            }
            else
            {
                echo $price;
            }; 
        ?>
    </p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于哈夫曼树应用得到一些问题
  • ¥15 使用sql server语句实现下面两个实验(需要代码和运行结果截图)
  • ¥20 用web解决,要给我一个完整的网页,符合上述的要求
  • ¥20 求个sql server代码和结果的图 两道题
  • ¥15 银河麒麟操作系统无法使用U盘
  • ¥100 寻找:光电二极管电路设计服务
  • ¥15 YOLOv5改进后的结构图
  • ¥15 全志v3s怎么设置高速时钟,使用的荔枝派zero开发板,串口2需要921600的波特率
  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁