gpt4 book ai didi

php - 在 WooCommerce 结帐中的小计之前移动优惠券表格

转载 作者:行者123 更新时间:2023-12-05 01:11:36 34 4
gpt4 key购买 nike

在我的 Storefront 子主题中,在结帐页面中,我试图将优惠券代码块移动到购物车总数上方和商品评论下方 enter image description here

我在 review-order.php 中看到,在正确的位置有以下钩子(Hook):

do_action( 'woocommerce_review_order_after_cart_contents' );

所以在functions.php文件中,我添加了:

remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
add_action( 'woocommerce_review_order_after_cart_contents', 'woocommerce_checkout_coupon_form' );

但是,优惠券 block 出现了两次......在订单评论上方而不是下方。

enter image description here

最佳答案

2021 年更新 使用:Move coupon form before payment section in WooCommerce checkout

作为钩子(Hook)woocommerce_review_order_after_cart_contents is located inside an html table</tr> 之间和 </tbody>标签,因此它需要显示在特定的 html 结构中,以避免您的问题。

以下将做到这一点:

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 文件中。经过测试并且有效。


如果您想直接显示优惠券表单,您可以在您的事件子主题(或事件主题)的 style.css 文件中添加以下内容:

.woocommerce-checkout .checkout_coupon.woocommerce-form-coupon {
display: block !important;
}

相关:Move coupon field after checkout payment in Woocommerce?

关于php - 在 WooCommerce 结帐中的小计之前移动优惠券表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62893614/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com