亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce:如果我將優惠券包裹在折疊元素中,則優惠券無法在購物車中使用

WooCommerce:如果我將優惠券包裹在折疊元素中,則優惠券無法在購物車中使用

PHP
守著星空守著你 2022-12-23 12:25:33
我想隱藏購物車中的優惠券字段。為此,我將其包裝在 Bootstrap 折疊元素中并添加display:none到現有的優惠券字段中。編輯:在@gael 發表評論后(WooCommerce:如果我將優惠券包裹在折疊元素中,優惠券將無法在購物車中使用),我發現,如果我在模板的其他位置顯示該表單,則該表單有效。但是現在它不再顯示任何成功或錯誤消息了?!這是我的代碼:<?phpadd_action( 'woocommerce_after_cart_table', 'display_coupon_form_below_proceed_checkout', 50 );function display_coupon_form_below_proceed_checkout() {   ?>    <small><a class="text-muted" data-toggle="collapse" href="#collapseCartCoupon" role="button" aria-expanded="false" aria-controls="collapseCartCoupon"><?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?></a></small>        <form class="woocommerce-coupon-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">            <div class="collapse" id="collapseCartCoupon">            <?php if ( wc_coupons_enabled() ) { ?>            <div class="coupon under-proceed">                <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" style="width: 100%" />                <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>" style="width: 100%"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>            </div>            <?php } ?>            </div>        </form>    <style>        .woocommerce table.shop_table .coupon {display: none !important;}    </style>    <?php}
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

我會覆蓋 WooCommerce 上的購物車頁面,以將優惠券包裝在折疊元素中。


可以通過將文件從模板復制wp-content/plugins/woocommerce/templates/cart/cart.php到wp-content/themes/yourtheme/woocommerce/cart/cart.php.


然后從 WooCommerce v4 中的第 142 行到第 150 行,您可以像這樣插入您的代碼段:


<?php if ( wc_coupons_enabled() ) { ?>

    <small><a class="text-muted" data-toggle="collapse" href="#collapseCartCoupon" role="button" aria-expanded="false" aria-controls="collapseCartCoupon"><?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?></a></small>

    <div class="coupon collapse"  id="collapseCartCoupon">

        <label for="coupon_code"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" /> <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>

        <?php do_action( 'woocommerce_cart_coupon' ); ?>

    </div>

<?php } ?>

由于我的主題已經在使用 Bootstrap,collapse該類已經隱藏了整個 div,因此我不必添加您的內聯樣式。


我確實測試過將它移到新<tr>的桌子底下,優惠券代碼仍然有效。我想它只需要在里面<form>...</form>就可以使用。


另請注意模板文件頂部來自 WooCommerce 的警告:


 * HOWEVER, on occasion WooCommerce will need to update template files and you

 * (the theme developer) will need to copy the new files to your theme to

 * maintain compatibility. We try to do this as little as possible, but it does

 * happen. When this occurs the version of the template file will be bumped and

 * the readme will list any important changes.


查看完整回答
反對 回復 2022-12-23
  • 1 回答
  • 0 關注
  • 87 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號