生命不息,奋斗不止/创造价值-传递价值-获得价值
所谓迷茫,就是才华配不上梦想 每一个让你难堪的现在,都有一个不够努力的曾经

修改WooCommerce Edit My Address页面

默认页面

在Wootique主题下,默认页面如下:

控制面板中的设置

如果不需要获取Shipping Address,可在WooCommerce > Settings控制面板中的Shipping项下,勾选 Only ship to the users billing address。当点击Edit进入地址修改页面时,Shipping Address将不再显示。

my-address.php

地址修改页面是由templates/myaccount文件夹下的my-address.php文件定义的,将文件复制到主题文件夹下,建议使用子主题,以Wootique主题为例,目的文件夹路径为themes/wootique-child/woocommerce/myaccount。

定义标题的语句:

$customer_id = get_current_user_id();

if ( get_option('woocommerce_ship_to_billing_address_only') == 'no' ) {
	$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Addresses', 'woocommerce' ) );
	$get_addresses    = array(
		'billing' => __( 'Billing Address', 'woocommerce' ),
		'shipping' => __( 'Shipping Address', 'woocommerce' )
	);
} else {
	$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Address', 'woocommerce' ) );
	$get_addresses    = array(
		'billing' =>  __( 'Billing Address', 'woocommerce' )
	);
}

将两处My Address改为My Information,将两处Billing Address改为My Information。

<p class="myaccount_address">
	<?php echo apply_filters( 'woocommerce_my_account_my_address_description', __( 'The following addresses will be used on the checkout page by default.', 'woocommerce' ) ); ?>
</p>

将以上语句中的The following address…改为The following information will be used when submitting quote by default.

form-edit-address.php

点击Edit,进入修改地址的页面。

默认页面:

billing-address_before

Billing Address修改页面是在form-edit-address.php文件中定义的。将文件复制到子主题文件夹下,以Wootique主题为例,目的路径为themes/wootique-child/woocommerce/myaccount。

<h3><?php if ($load_address=='billing') _e( 'Billing Address', 'woocommerce' ); else _e( 'Shipping Address', 'woocommerce' ); ?></h3>

将Billing Address改为My Information。

以下代码定义Save Address按钮:

<p>
	<input type="submit" class="button" name="save_address" value="<?php _e( 'Save Address', 'woocommerce' ); ?>" />
	<?php $woocommerce->nonce_field('edit_address') ?>
	<input type="hidden" name="action" value="edit_address" />
</p>

将Save Address改为Save Update。

function.php

可通过woocommerce_billing_fields filter修改。关于woocommerce_billing_fields filter可参见“通过挂钩自定义Checkout字段”。

将以下代码复制到主题的function.php文件中,建议使用子主题:

/**
 * Customize Billing Address page
 */

add_filter( 'woocommerce_billing_fields' , 'custom_override_billing' );

function custom_override_billing( $fields ) {
     $fields['billing_first_name']['label'] = 'Your Name';
     $fields['billing_company']['label'] = 'Company Name';
     $fields['billing_company']['class'] = array( 'form-row-last');
     $fields['billing_email']['label'] = 'Email Address';
     $fields['billing_phone']['label'] = 'Phone';
     $fields['billing_phone']['required'] = false;     

     unset($fields['billing_last_name']);     
     unset($fields['billing_country']);
     unset($fields['billing_address_1']);
     unset($fields['billing_address_2']);
     unset($fields['billing_city']);
     unset($fields['billing_state']);
     unset($fields['billing_postcode']);

     return $fields;
}

以不获取Shipping Address为例,修改后:

edit-my-address_after

billing-address_after

参考资料:
Remove fields on Edit Address

赞(0)
未经允许不得转载:jack361博客 » 修改WooCommerce Edit My Address页面

如果你爱我或恨我,请↓

联系我