在“按订单付款”页面上保存开票和运输字段数据Woocommerce

时间:2020-09-21 19:32:08

标签: php wordpress woocommerce

灵感来自:Display billing and shipping fields in “Pay to order” page Woocommerce

如何更新客户帐户/资料和元订单中的账单和运输数据?

或者执行注释@Outsource WordPress的操作(然后您可以通过AJAX调用(通过添加新按钮)更新订单元值。

<!-- Display Information -->
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
<address>
    <?php echo wp_kses_post( $order->get_formatted_billing_address( __( 'N/A', 'woocommerce' ) ) ); ?>
    <?php if ( $order->get_billing_phone() ) : ?>
        <p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
    <?php endif; ?>
    <?php if ( $order->get_billing_email() ) : ?>
        <p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
    <?php endif; ?>
</address>

<h2 class="woocommerce-column__title"><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>
<address>
    <?php echo wp_kses_post( $order->get_formatted_shipping_address( __( 'N/A', 'woocommerce' ) ) ); ?>
</address>

<!-- Form -->
<h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_billing_form', $order ); ?>
<div class="woocommerce-billing-fields__field-wrapper">
    <?php
    $fields = WC()->checkout->get_checkout_fields( 'billing' );
    foreach ( $fields as $key => $field ) {
        $field_name = $key;

        if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
            $field['value'] = $order->{"get_$field_name"}( 'edit' );
        } else {
            $field['value'] = $order->get_meta( '_' . $field_name );
        }   
        woocommerce_form_field( $key, $field, $field['value'] );
    }
    ?>
</div>
<?php do_action( 'woocommerce_after_checkout_billing_form', $order ); ?>

<h3><?php _e( 'Shipping details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_shipping_form', $order ); ?>
<div class="woocommerce-shipping-fields__field-wrapper">
    <?php
    $fields = WC()->checkout->get_checkout_fields( 'shipping' );
    foreach ( $fields as $key => $field ) {
        $field_name = $key;

        if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
            $field['value'] = $order->{"get_$field_name"}( 'edit' );
        } else {
            $field['value'] = $order->get_meta( '_' . $field_name );
        }   
        woocommerce_form_field( $key, $field, $field['value'] );
    }
    ?>
</div>
<?php do_action( 'woocommerce_after_checkout_shipping_form', $order ); ?>

0 个答案:

没有答案