I have recently come across a problem of which I has me a little confused. Within my WP setup, I have a basic WooCommerce solution, (For the theme I am using the Timber starter theme to make use of twig templating). As well as this, I am using a custom post type named 'sites'. Sites represent a list of construction sites, not to be confused with websites.
The Sites CPT has X Advanced custom fields 'fields', as well as the standard 'title', the ACF fields being:
- PO Number (po_number) -> String -> required / not null
- Job Number (job_number) -> String -> required / not null
- Street address (street_address) -> String -> required / not null
- Office Name (office_name) -> String -> required / not null
- Town (town) -> String -> required / not null
- County (county) -> String -> optional / nullable
- Post Code (post_code) -> String -> required / not null
So most of the above from the admins side are required, so we know the data will be present.
The issue I am having is that, when on the checkout, we would like fields matching the above, as well as an email address field (required) and a contact number field (required).
The purpose being that, when a customer types in their 'Job Number' and hits a 'Find' button, a query is kicked off matching this Job Number against the Job Number field on the Custom Post Type, and if a match is found, the other fields from that record are filled into the rest of the checkout form.
In terms of trying out a solution, the only thing I could thing of was a database query to match and return the data, but I am fairly new to WP as a whole and there seem to be concepts such as Ajax having a specific use case in WP, the DB structure seems quite complex, so I thought I would ask here and see if anyone had a solution.
As of yet, there is no code to show otherwise I would, and in terms of the WooCommerce templates, they are all standard and have not been modified.
Just to summarise, the goal is:
Customer goes to checkout -> Enters their already known Job Number and hits 'Find' -> Some sort of query is ran to match that Job Number against a CPT ACF field of Job Number -> If a match is found, return those fields and fill the Woo Checkout fields in with that data.
Any ideas solution or suggestions are very welcome, thank you in advance.