Php 如何在结帐页面上显示订单摘要?

Php 如何在结帐页面上显示订单摘要?,php,wordpress,woocommerce,wordpress-theming,hook-woocommerce,Php,Wordpress,Woocommerce,Wordpress Theming,Hook Woocommerce,我正在做一个woo commerce主题,这很好,但在结账页面上,客户希望更改某些区块的顺序。所以他想在订单汇总之前移动付款方式。我通过在function.php中添加下面给出的代码实现了这一点。代码运行良好,但添加代码后,我在结帐页面上看不到订单摘要。我看不到小计、装运和总成本。我不知道这个代码有什么问题。请帮我解决这个问题 add_action( 'woocommerce_checkout_order_review', 'reordering_checkout_order_review',

我正在做一个woo commerce主题,这很好,但在结账页面上,客户希望更改某些区块的顺序。所以他想在订单汇总之前移动付款方式。我通过在function.php中添加下面给出的代码实现了这一点。代码运行良好,但添加代码后,我在结帐页面上看不到订单摘要。我看不到小计、装运和总成本。我不知道这个代码有什么问题。请帮我解决这个问题

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', 'after_custom_checkout_payment', 9 );
    add_action( 'woocommerce_checkout_order_review', 'custom_checkout_place_order', 20 );
}

function after_custom_checkout_payment() {
    ?>
    <div id="before-order-table" class="woocommerce-checkout-custom-text">
        <h3><?php _e("Your order", "woocommerce"); ?></h3>
        <p><?php /* _e("I have accepted the terms and bla bla bla", "woocommerce"); */?></p>
    </div>
    <?php
}

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' );
    }
}
add_action('woocommerce_checkout_order_review','reordering_checkout_order_review',1);
函数重新排序\签出\订单\审核(){
删除操作(“woocommerce\u checkout\u order\u review”和“woocommerce\u checkout\u payment”,20);
添加操作('woocommerce\u checkout\u order\u review'、'custom\u checkout\u payment',8);
添加操作('woocommerce\u checkout\u order\u review','after\u custom\u checkout\u payment',9);
添加操作('woocommerce\u checkout\u order\u review'、'custom\u checkout\u place\u order',20);
}
自定义结账付款后的函数(){
?>



您还可以通过以下方式进行检查:

add_filter( 'woocommerce_checkout_fields' , 'custom_order_comments_checkout_fields' );
function custom_order_comments_checkout_fields( $fields ) {
    if ( !WC()->cart->is_empty()):
    $output = '';
    $count = 0;
    $cart_item_count = WC()->cart->get_cart_contents_count();
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ):
        $count++;
        // Displaying the product title
        $output .= 'Product title: ' . $cart_item['data']->post->post_title;
        // New line (for next item)
        if($count < $cart_item_count)
            $output .= '';
    endforeach;
    $fields['order']['order_comments']['default'] = $output;
    endif;
    return $fields;
}
add_filter('woocommerce_checkout_fields'、'custom_order_comments_checkout_fields'、'custom_comments_comments_comments_checkout_fields');
函数自定义\订单\注释\签出\字段($fields){
如果(!WC()->购物车->为空()):
$output='';
$count=0;
$cart\u item\u count=WC()->cart->get\u cart\u contents\u count();
foreach(WC()->cart->get_cart()作为$cart\u item\u key=>$cart\u item):
$count++;
//显示产品标题
$output.=“产品标题:”。$cart\u项目['data']->post->post\u标题;
//新行(用于下一项)
如果($count<$cart\u item\u count)
$output.='';
endforeach;
$fields['order']['order_comments']['default']=$output;
endif;
返回$fields;
}

function.php文件我也尝试过完全删除我的所有代码,并用你的代码替换。但不起作用