1 回答

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.
- 1 回答
- 0 關注
- 87 瀏覽
添加回答
舉報