在WooCommerce结帐小计之前移动优惠券表格 [英] Move coupon form before subtotal in WooCommerce checkout
问题描述
在店面子主题中,在结帐页面中,我试图将优惠券代码块移动到购物车总额上方和商品评论下方
In my Storefront child theme, in the checkout page, I am trying to move the coupon code block just above the cart totals and below the item review
我在 review-order.php
中看到在正确的位置有以下挂钩:
I see in review-order.php
that there's the following hook just at the right place:
do_action( 'woocommerce_review_order_after_cart_contents' );
因此,在functions.php文件中,我添加了:
So in the functions.php file, I added:
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
add_action( 'woocommerce_review_order_after_cart_contents', 'woocommerce_checkout_coupon_form' );
但是,优惠券块出现了两次...并且位于订单查看上方,而不是下方.
But, the coupon block appears twice...and above the order review instead of below.
推荐答案
作为挂钩 woocommerce_review_order_after_cart_contents
位于html表内,位于</tr>
和</tbody>
标记之间显示在特定的html结构中,以避免出现问题.
As the hook woocommerce_review_order_after_cart_contents
is located inside an html table in between </tr>
and </tbody>
tags, so it requires to be displayed inside a specific html structure, to avoid your issue.
以下将执行此操作:
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
add_action( 'woocommerce_review_order_after_cart_contents', 'woocommerce_checkout_coupon_form_custom' );
function woocommerce_checkout_coupon_form_custom() {
echo '<tr class="coupon-form"><td colspan="2">';
wc_get_template(
'checkout/form-coupon.php',
array(
'checkout' => WC()->checkout(),
)
);
echo '</tr></td>';
}
代码进入活动子主题(或活动主题)的functions.php文件中.经过测试并可以正常工作.
Code goes in functions.php file of the active child theme (or active theme). tested and works.
如果要直接显示优惠券表单,可以在活动子主题(或活动主题)的style.css文件中添加以下内容:
If you want to display the coupon form directly, you can add the following in style.css file oof your active child theme (or active theme):
.woocommerce-checkout .checkout_coupon.woocommerce-form-coupon {
display: block !important;
}
这篇关于在WooCommerce结帐小计之前移动优惠券表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!