Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Order Note with Addresses #134

Open
TimBHowe opened this issue Oct 12, 2022 · 2 comments
Open

Save Order Note with Addresses #134

TimBHowe opened this issue Oct 12, 2022 · 2 comments

Comments

@TimBHowe
Copy link
Contributor

Add the ability to save the order note with the addressbook so it can will be autofilled as well.

I was hoping to ask a quick question regarding the WooCommerce Address Book plugin for WordPress you are credited with authoring https://en-gb.wordpress.org/plugins/woo-address-book/ - is it possible to save the 'order notes' field data alongside the address information? The idea is that if a customer always has the same instruction for a particular address this would be auto-filled alongside the rest.

I am working on a client's site which uses the order notes field when a particular shipping option is selected, however I don't believe it currently saves that information which would be useful for what they have asked. The 'order notes' is a base WooCommerce feature found in woocommerce/templates/checkout/form-shipping.php and is part of the 'shipping' fields.

@TimBHowe
Copy link
Contributor Author

Might want to make this it's own field like "Delivery Instructions" and leave the order note as is

We suggest looking at the following:

  • wc_address_book_addresses - Gets the customer's addresses with field values
  • woocommerce_checkout_update_customer - Update the customer data with the information entered on checkout.
  • ​Also the Woo Hooks, Actions and Filters we use in the plugin constructor.

@matt-h
Copy link
Member

matt-h commented Oct 13, 2022

The Order Note field is its own checkout field which is not linked to the Billing or Shipping addresses. In order to have it linked to one of them would take a lot of override code in both the checkout in order to change it when selecting address. But you would also need to customize the WooCommerce core Edit Address pages to both show and save the custom fields to be able to save them to an address. This could get very messy having to deal with saving and retrieving the data.

A much easier solution would be to just add another Textarea field to either Billing or Shipping address.
Something like this:

add_filter( 'woocommerce_shipping_fields', 'custom_override_shipping_fields' );
function custom_override_shipping_fields( $fields ) {
	$fields['shipping_instructions'] = array(
		'label'       => __('Delivery Instructions', 'woocommerce'),
		'placeholder' => esc_attr__(
			'Notes about your order, e.g. special notes for delivery.',
			'woocommerce'
		),
		'type'        => 'textarea',
		'class'       => array( 'notes' )
	);

	return $fields;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants