Woocommerce 将可编辑的地址字段添加到电子商务发票页面

Woocommerce 将可编辑的地址字段添加到电子商务发票页面,woocommerce,hook-woocommerce,custom-wordpress-pages,Woocommerce,Hook Woocommerce,Custom Wordpress Pages,请原谅这样一个基本的问题。我对WooCommerce主题开发还比较陌生,我真正想了解wordpress是如何处理客户数据的,这样我就可以学习如何处理客户数据了。如果这个问题仍然太宽泛,(我上一个问题因为这个原因关闭了),我甚至欢迎一些链接,帮助我指出正确的方向,并解释我所关注的领域 我试图做的是在我们给客户发送发票时,将可编辑的地址字段添加到客户看到的页面。(表单pay.php) 最初,我尝试使用functions.php中每个字段的以下代码变体手动添加字段,并从order-pay.php调用它

请原谅这样一个基本的问题。我对WooCommerce主题开发还比较陌生,我真正想了解wordpress是如何处理客户数据的,这样我就可以学习如何处理客户数据了。如果这个问题仍然太宽泛,(我上一个问题因为这个原因关闭了),我甚至欢迎一些链接,帮助我指出正确的方向,并解释我所关注的领域

我试图做的是在我们给客户发送发票时,将可编辑的地址字段添加到客户看到的页面。(表单pay.php)

最初,我尝试使用functions.php中每个字段的以下代码变体手动添加字段,并从order-pay.php调用它:

<p class="form-row form-row-first">
<label for="billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>

*

这些字段现在正确显示在发票页面上,该页面显示我已添加到发票中的所有地址详细信息。我只需要了解我需要在按钮上附加什么逻辑来告诉WooCommerce更新记录


正如我所说的,我认识到这是一个基本的问题,但到目前为止,我还没有找到一个解释,特别是在更新发票而不是购物车的情况下有效。

Hi@fraserYT我也在寻找解决方案!你明白了吗?谢谢哈维,你好。恐怕我还没有弄清事情的真相,但我仍在低调地做这件事。当我最终解决它时,我会在这里更新。
<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 ); ?>