如果购物车中有1件或更多商品,我如何才能显示购物篮通知?

时间:2016-04-27 15:32:20

标签: php woocommerce

我要求用户购物车的总价格显示在标题中,但我只希望在用户购物车中有1个或更多商品时显示。有谁知道我需要添加到代码中执行此操作?我已经尝试了一些我在网上找到的建议,但没有一个有效。

这是我当前的HTML代码(不起作用):

     <?php if ( $cart_contents_count > 0 ) { ?>
        <a class="cart-contents" href="http://localhost:8888/devo-wordpress/cart">
            <div id=basket>
                <span class="tot-price"><?php echo WC()->cart->get_cart_total(); ?></span>
                <span class="glyphicons glyphicons-shopping-cart"></span>
            </div>
        </a>    }
    <?php
    endif; ?>

1 个答案:

答案 0 :(得分:1)

尝试理解if语句,如果这样的语句可以使用

if(CONDITION){

}

或者像这样

if ($value):

endif;

如果您只使用PHP,请使用第一种情况 如果你想在它之间插入html内容,那就是第二个

您的代码包含

<?php if ( $cart_contents_count > 0 ) { ?>

作为开始和

<?php endif; ?>

这个结尾哪个错了。像这样使用

    <?php if ( $cart_contents_count > 0 ) : ?>
        <a class="cart-contents" href="http://localhost:8888/devo-wordpress/cart">
            <div id=basket>
                <span class="tot-price"><?php echo WC()->cart->get_cart_total(); ?></span>
                <span class="glyphicons glyphicons-shopping-cart"></span>
            </div>
        </a>
    <?php endif; ?>