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 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!