Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WooCommerce modify shipping fields in edit My Account page WordPress

I ship to a third-party email address provided by my customers. I'm using the Wordpress Karma theme with a WooCommerce plug in. I have already edited the functions.php file for my child theme to delete the land address fields and add an email address field in Shipping Address portion of the checkout form, but I need to do the same thing when my customer clicks on the My Account page and hits edit Shipping Address. I also need to edit the Order Received email that goes out to customers and includes the Shipping Address. Not sure what the right hook is to use. Would prefer to make edits to functions.php so I don't lose these mods when I version up my WooCommerce plug in. [[LINK href="https://accreditedinvestorsolutions.com"]]Here's my website.[[/LINK]]

Answers (2)

2013-02-04

Fahad Murtaza answers:

I can look into it if you send me access details.


Lowell Ness comments:

URL is https://www.accreditedinvestorsolutions.com


Fahad Murtaza comments:

Well, if you can send me FTP and login to wordpress, I can help. Send it via message.


Lowell Ness comments:

I'm just looking for the right code hook to use. I don't need you to do that for me. Here's what I've tried so far. The first two filter hooks worked to change the shipping fields in the checkout form (there's a nice easy to follow tutorial available for that one), but the third one for 'woocommerce_process_myaccount_field_' didn't change the shipping fields in the edit Shipping Address page on My Account. The WooCommerce API docs say this is a valid filter hook, but it must not be the correct hook because it didn't change the page I needed to change. The page I'm trying to change comes up when you hit My Account and then you hit edit Shipping Address. Or, it's possible my filter is not correctly coded.


add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_first_name']['placeholder'] = 'Recipient First Name';
$fields['shipping']['shipping_last_name']['placeholder'] = 'Recipient Last Name';
$fields['shipping']['shipping_company']['placeholder'] = 'Company to receive certification';
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_city']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_state']);
$fields['shipping']['shipping_email'] = array(
'label' => __('Email Address', 'woocommerce'),
'placeholder' => _x('Email address to receive certification', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
$fields['order']['order_comments']['placeholder'] = 'Notes about your order, e.g. special notes for delivery of our certification to additional recipients';
return $fields;
}

add_filter( 'woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');
function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys['shipping']['shipping_email'] = 'Shipping Email';
return $keys;
}
add_filter( 'woocommerce_process_myaccount_field_' , 'custom_override_procees_myaccount_field_' );
function custom_override_proceess_myaccount_field_( $keys ) {
$keys['shipping']['shipping_first_name']['placeholder'] = 'Recipient First Name';
$keys['shipping']['shipping_last_name']['placeholder'] = 'Recipient Last Name';
$keys['shipping']['shipping_company']['placeholder'] = 'Company to receive certification';
unset($keys['shipping']['shipping_address_1']);
unset($keys['shipping']['shipping_address_2']);
unset($keys['shipping']['shipping_city']);
unset($keys['shipping']['shipping_postcode']);
unset($keys['shipping']['shipping_country']);
unset($keys['shipping']['shipping_state']);
$keys['shipping']['shipping_email'] = array(
'label' => __('Email Address', 'woocommerce'),
'placeholder' => _x('Email address to receive certification', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
return $keys;
}

2013-02-04

Dbranes answers:

In the core code for woocommerce_save_address() you have:


// Hook to allow modification of value
$_POST[$key] = apply_filters('woocommerce_process_myaccount_field_' . $key, $_POST[$key]);


so it looks like you will have to replace $key in

woocommerce_process_myaccount_field_.$key

with your relavant $key, in your add_filter code.

So you could try out filters like:

woocommerce_process_myaccount_field_shipping

woocommerce_process_myaccount_field_shipping_first_name

woocommerce_process_myaccount_field_shipping_last_name

woocommerce_process_myaccount_field_shipping_company

...