【问题标题】:Change payment methods location before order details table in Woocommerce在 Woocommerce 中的订单详细信息表之前更改付款方式位置
【发布时间】:2019-01-21 03:51:56
【问题描述】:

我需要稍微更改一下默认的 Woocommerce 结帐。我需要将付款选项移动到订单审核表上方,同时将“下订单”按钮保留在订单审核表下方的底部。我目前有

    remove_action('woocommerce_checkout_order_review','woocommerce_checkout_payment', 20 );
    add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 5 );

这会将支付框移动到桌子上方,但它也会移动按钮。如何让按钮保持在底部?

【问题讨论】:

    标签: php wordpress templates woocommerce checkout


    【解决方案1】:

    您将在下面找到重新排序结帐订单审查部分的必要代码。此代码会将付款方式和网关放在结帐审查订单表之前,并将“下订单”按钮保留在最后。

    代码:

    add_action( 'woocommerce_checkout_order_review', 'reordering_checkout_order_review', 1 );
    function reordering_checkout_order_review(){
        remove_action('woocommerce_checkout_order_review','woocommerce_checkout_payment', 20 );
        add_action( 'woocommerce_checkout_order_review', 'custom_checkout_payment', 8 );
        add_action( 'woocommerce_checkout_order_review', 'custom_checkout_place_order', 20 );
    }
    
    function custom_checkout_payment() {
        $checkout = WC()->checkout();
        if ( WC()->cart->needs_payment() ) {
            $available_gateways = WC()->payment_gateways()->get_available_payment_gateways();
            WC()->payment_gateways()->set_current_gateway( $available_gateways );
        } else {
            $available_gateways = array();
        }
    
        if ( ! is_ajax() ) {
            // do_action( 'woocommerce_review_order_before_payment' );
        }
        ?>
        <div id="payment" class="woocommerce-checkout-payment-gateways">
            <?php if ( WC()->cart->needs_payment() ) : ?>
                <ul class="wc_payment_methods payment_methods methods">
                    <?php
                    if ( ! empty( $available_gateways ) ) {
                        foreach ( $available_gateways as $gateway ) {
                            wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
                        }
                    } else {
                        echo '<li class="woocommerce-notice woocommerce-notice--info woocommerce-info">';
                        echo apply_filters( 'woocommerce_no_available_payment_methods_message', WC()->customer->get_billing_country() ? esc_html__( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ) : esc_html__( 'Please fill in your details above to see available payment methods.', 'woocommerce' ) ) . '</li>'; // @codingStandardsIgnoreLine
                    }
                    ?>
                </ul>
            <?php endif; ?>
        </div>
        <?php
    }
    
    function custom_checkout_place_order() {
        $checkout          = WC()->checkout();
        $order_button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
        ?>
        <div id="payment-place-order" class="woocommerce-checkout-place-order">
            <div class="form-row place-order">
                <noscript>
                    <?php esc_html_e( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce' ); ?>
                    <br/><button type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( 'Update totals', 'woocommerce' ); ?>"><?php esc_html_e( 'Update totals', 'woocommerce' ); ?></button>
                </noscript>
    
                <?php wc_get_template( 'checkout/terms.php' ); ?>
    
                <?php do_action( 'woocommerce_review_order_before_submit' ); ?>
    
                <?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '">' . esc_html( $order_button_text ) . '</button>' ); // @codingStandardsIgnoreLine ?>
    
                <?php do_action( 'woocommerce_review_order_after_submit' ); ?>
    
                <?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
            </div>
        </div>
        <?php
        if ( ! is_ajax() ) {
            do_action( 'woocommerce_review_order_after_payment' );
        }
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试和工作。

    【讨论】:

    • 非常感谢!这太棒了。有没有办法在订单审核表上方添加标题和段落?喜欢和 h3 和下面的 p?
    • 谢谢!这是新问题:stackoverflow.com/questions/51848171/…
    • 当然!对不起,我是新来的,必须熟悉这里的一切 iis 是如何工作的:)
    猜你喜欢
    • 2015-01-28
    • 2021-11-03
    • 2018-04-05
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2023-01-22
    • 1970-01-01
    相关资源
    最近更新 更多