自定义 Wordpress Woocommerce 帐单地址编辑表单 [英] Customize the Wordpress Woocommerce billing address edit forms
问题描述
默认情况下,Woocommerce 有两种类型的地址,分别是账单地址和送货地址,这些信息可以在我的帐户页面进行编辑,点击编辑"链接,表单将在新窗口中打开.
By default, Woocommerce has two types of addresses which are Billing and Delivery address, and these informations can be edited from My Account page, you click the "edit" link, form opens in a new window.
但这就是我希望帐户页面的样子:
But this is what, I want the account page to look like:
当用户访问我的帐户"页面时,我希望在同一页面上同时编辑 [账单 (facturacion) 和送货地址 (datosenvio)] 表单.我怎样才能做到这一点?
When the user visits the My Account page, I would like to have both [the billing (facturacion) and shipping address (datos envio)] edit forms there on the same page. How can I achieve this?
我想在同一个页面中使用两个表单,而不是两个不同的表单.
I want to have both forms in the same page instead in two different ones.
我一直在尝试分离"两种形式,让它们在同一页面中并排放置,而不是将它们放在两个不同的页面/实例中.
I have been trying to "separate" both forms and have them one next to the other in the same page instead of having them in two different page/instances.
文件 form-edit-address 包含表单.
The file form-edit-address contains the forms.
这是我尝试过的:
在它读取的代码的开头
$page_title = ( $load_address === 'billing' ) ? __( 'Billing Address', 'woocommerce' );
我删除了运输位.但打破了一切.显然,这里是我必须砍一点来呈现帐单或运输表格的地方,我的经验有限,因此我一直在尝试各种组合,例如盲人行走.有人可以帮助我理解此代码以对其进行自定义吗?
I removed the shipping bit. but breaks all. clearly here is where i have to chop a bit to render billing or shipping forms, my experience is limited with php so I have been trying all sorts of combinations like walking blind. Can somebody help me understand this code to customize it?
这是未修改的代码:
<?php
/**
* Edit address form
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce, $current_user;
$page_title = ( $load_address === 'billing' ) ? __( 'Billing Address', 'woocommerce' ) : __( 'Shipping Address', 'woocommerce' );
get_currentuserinfo();
?>
<?php wc_print_notices(); ?>
<?php if ( ! $load_address ) : ?>
<?php wc_get_template( 'myaccount/my-address.php' ); ?>
<?php else : ?>
<form method="post">
<h3><?php echo apply_filters( 'woocommerce_my_account_edit_address_title', $page_title ); ?></h3>
<?php foreach ( $address as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, ! empty( $_POST[ $key ] ) ? wc_clean( $_POST[ $key ] ) : $field['value'] ); ?>
<?php endforeach; ?>
<p>
<input type="submit" class="button big" name="save_address" value="<?php _e( 'Save Address', 'woocommerce' ); ?>" />
<?php wp_nonce_field( 'woocommerce-edit_address' ); ?>
<input type="hidden" name="action" value="edit_address" />
</p>
</form>
<?php endif; ?>
推荐答案
这是您的方法.
<?php
// get the user meta
$userMeta = get_user_meta(get_current_user_id());
// get the form fields
$countries = new WC_Countries();
$billing_fields = $countries->get_address_fields( '', 'billing_' );
$shipping_fields = $countries->get_address_fields( '', 'shipping_' );
?>
<!-- billing form -->
<?php
$load_address = 'billing';
$page_title = __( 'Billing Address', 'woocommerce' );
?>
<form action="/my-account/edit-address/billing/" class="edit-account" method="post">
<h2><?php echo apply_filters( 'woocommerce_my_account_edit_address_title', $page_title ); ?></h2>
<?php do_action( "woocommerce_before_edit_address_form_{$load_address}" ); ?>
<?php foreach ( $billing_fields as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $userMeta[$key][0] ); ?>
<?php endforeach; ?>
<?php do_action( "woocommerce_after_edit_address_form_{$load_address}" ); ?>
<p>
<input type="submit" class="button" name="save_address" value="<?php esc_attr_e( 'Save Address', 'woocommerce' ); ?>" />
<?php wp_nonce_field( 'woocommerce-edit_address' ); ?>
<input type="hidden" name="action" value="edit_address" />
</p>
</form>
<!-- shipping form -->
<?php
$load_address = 'shipping';
$page_title = __( 'Shipping Address', 'woocommerce' );
?>
<form action="/my-account/edit-address/shipping/" class="edit-account" method="post">
<h2><?php echo apply_filters( 'woocommerce_my_account_edit_address_title', $page_title ); ?></h2>
<?php do_action( "woocommerce_before_edit_address_form_{$load_address}" ); ?>
<?php foreach ( $shipping_fields as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $userMeta[$key][0] ); ?>
<?php endforeach; ?>
<?php do_action( "woocommerce_after_edit_address_form_{$load_address}" ); ?>
<p>
<input type="submit" class="button" name="save_address" value="<?php esc_attr_e( 'Save Address', 'woocommerce' ); ?>" />
<?php wp_nonce_field( 'woocommerce-edit_address' ); ?>
<input type="hidden" name="action" value="edit_address" />
</p>
</form>
这篇关于自定义 Wordpress Woocommerce 帐单地址编辑表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!