drxyaox153896 2019-07-03 09:25
浏览 35

提交优惠券时回声但是无效的WooCommerce

I added this code on a page I am building:

<div class="coupon">

    <?php if( !WC()->cart->get_coupons() ) {
    ?>

    <form class="checkout_coupon woocommerce-form-coupon" method="post">

        <p style="color:white;"><?php esc_html_e( 'Kortingscode', 'woocommerce' ); ?></p>

        <p class="form-row form-row-first">
            <input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" id="coupon_code" value="" />
        </p>

        <p class="form-row form-row-last">
            <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_html_e( 'Apply coupon', 'woocommerce' ); ?></button>
        </p>

        <div class="clear"></div>
    </form><?php
}
?>
    <?php if( !WC()->cart->get_coupons() ) { ?>
    <p class="wrong-code">Wrong coupon entered</p>
    <?php } ?>

    <?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
    <p>Active coupon: <?php echo esc_attr( sanitize_title( $code ) ); ?></p>
    <p><?php wc_cart_totals_coupon_html( $coupon ); ?></p>
    <?php endforeach; ?>

</div>

Now the text 'Wrong coupon entered' is shown from the beginning before there is any coupon submitted. Only if a right coupon is submitted it doesn't show up. I want to add another rule to it which also checks for the last submitted code if it is valid or not so the wrong coupon text only shows up when the customer submitted a coupon AND it is invalid.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分