【问题标题】:Move coupon form before subtotal in WooCommerce checkout在 WooCommerce 结帐中的小计之前移动优惠券表格
【发布时间】:2020-11-03 16:43:59
【问题描述】:

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

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

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' );

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

【问题讨论】:

    标签: php wordpress woocommerce checkout storefront


    【解决方案1】:

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

    由于woocommerce_review_order_after_cart_contentsis 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?

    【讨论】:

    • 嘿@LoicTheAstec!感谢您的回答。似乎它在正确的位置显示优惠券表格,但随后出现表格正在更新并且优惠券表格消失的符号......知道为什么吗?
    • 在这里不起作用。也许是一个插件。我现在正在检查。
    • 好的,知道了。我只显示包含checkout_coupon woocommerce-form-coupon 的部分,所以我必须display: block !important
    • 每个寻找更好解决方案的人我都会建议This topic
    猜你喜欢
    • 2021-04-17
    • 1970-01-01
    • 2021-12-11
    • 2016-02-25
    • 2014-09-08
    • 2021-01-03
    • 2017-07-13
    • 2018-08-22
    • 1970-01-01
    相关资源
    最近更新 更多