Hi,
In admin=>orders=>edit of any order, the page title is something like "Order #56", for example. To make the order number match a specific naming convention, I need to extract the customer/recipient's name and the country name from the delivery address to add to the page title. How do I do that?
I know the code displaying all data of an order is in admin/actions/orders/views/edit.php, and I am aware I probably need to change the core code. I tried extracting the data mentioned above but failed.
Thanks in advance for any help.
Eddy
Order Edit: Extract name and country from delivery address
- Kofod95
- VIP Member
- Posts: 437
- Joined: Sat Feb 06, 2021 7:38 pm
- Has thanked: 62 times
- Been thanked: 106 times
Re: Order Edit: Extract name and country from delivery address
Instead of editing core, I think you could hi-jack the action and redirect it to your custom action with a hook.
Alternatively, you might be able to just hook in some JavaScript to append the data to the title.
If you look in invoice.php, I think you can see how to get the data you need.
Sorry for being brief and vague, I'll try to expound on stuff, if you need it!
//Daniel
Alternatively, you might be able to just hook in some JavaScript to append the data to the title.
If you look in invoice.php, I think you can see how to get the data you need.
Sorry for being brief and vague, I'll try to expound on stuff, if you need it!
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
-
- VIP Member
- Posts: 55
- Joined: Fri Nov 06, 2020 10:36 am
- Has thanked: 19 times
- Been thanked: 2 times
Re: Order Edit: Extract name and country from delivery address
Unlike customer data, name and country in delivery & billing addresses are merged into $address for invoice.php, so I probably need to do my own database query to get those data separately - at least, that's the only way I can think of. I do not know enough to code a hook or js to change the behavior of the original code. Probably time for me to learn coding in new ways.Kofod95 wrote: ↑Sat Jan 28, 2023 8:18 am Instead of editing core, I think you could hi-jack the action and redirect it to your custom action with a hook.
Alternatively, you might be able to just hook in some JavaScript to append the data to the title.
If you look in invoice.php, I think you can see how to get the data you need.
Sorry for being brief and vague, I'll try to expound on stuff, if you need it!
//Daniel
- Kofod95
- VIP Member
- Posts: 437
- Joined: Sat Feb 06, 2021 7:38 pm
- Has thanked: 62 times
- Been thanked: 106 times
Re: Order Edit: Extract name and country from delivery address
I think you could make a hook in includes/hooks/admin/orders listening to inject_redirects, which would have to check for action=edit and then redirect to action=your_custom_edit.
If going the JS-way, there is a function that gets elements from classes (https://www.w3schools.com/jsref/met_doc ... ssname.asp) after which you should be able to append your custom data. So still includes/hooks/admin/orders, but probably just listening to injectSiteend (or whatever it's called) with some php that adds the data to variables that you then add to the JS (there are examples of this last part in some of the supporters code - in fact all that adds a new tab for product-edits, if I remember correctly). The data should be obtainable with either (or maybe both) $order->info or $customer_data->get, but I don't remember exactly how.
//Daniel
If going the JS-way, there is a function that gets elements from classes (https://www.w3schools.com/jsref/met_doc ... ssname.asp) after which you should be able to append your custom data. So still includes/hooks/admin/orders, but probably just listening to injectSiteend (or whatever it's called) with some php that adds the data to variables that you then add to the JS (there are examples of this last part in some of the supporters code - in fact all that adds a new tab for product-edits, if I remember correctly). The data should be obtainable with either (or maybe both) $order->info or $customer_data->get, but I don't remember exactly how.
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
-
- VIP Member
- Posts: 55
- Joined: Fri Nov 06, 2020 10:36 am
- Has thanked: 19 times
- Been thanked: 2 times
Re: Order Edit: Extract name and country from delivery address
Thanks, Daniel - much appreciated! I'll do my best and give it a try. Cheers, EddyKofod95 wrote: ↑Sat Jan 28, 2023 10:10 pm I think you could make a hook in includes/hooks/admin/orders listening to inject_redirects, which would have to check for action=edit and then redirect to action=your_custom_edit.
If going the JS-way, there is a function that gets elements from classes (https://www.w3schools.com/jsref/met_doc ... ssname.asp) after which you should be able to append your custom data. So still includes/hooks/admin/orders, but probably just listening to injectSiteend (or whatever it's called) with some php that adds the data to variables that you then add to the JS (there are examples of this last part in some of the supporters code - in fact all that adds a new tab for product-edits, if I remember correctly). The data should be obtainable with either (or maybe both) $order->info or $customer_data->get, but I don't remember exactly how.
//Daniel
- Kofod95
- VIP Member
- Posts: 437
- Joined: Sat Feb 06, 2021 7:38 pm
- Has thanked: 62 times
- Been thanked: 106 times
Re: Order Edit: Extract name and country from delivery address
I wish you good luck!
If you get stuck, I think I could be a little more helpful, and maybe others know better than me - as a PRO-Supporter you have of course also the option to post in the VIP-forum to get expert advice from core coders, should we fail to solve things here. So at least there is a fallback;)
-anyway, I look forward to hear of your progress!
//Daniel
If you get stuck, I think I could be a little more helpful, and maybe others know better than me - as a PRO-Supporter you have of course also the option to post in the VIP-forum to get expert advice from core coders, should we fail to solve things here. So at least there is a fallback;)
-anyway, I look forward to hear of your progress!
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
-
- VIP Member
- Posts: 55
- Joined: Fri Nov 06, 2020 10:36 am
- Has thanked: 19 times
- Been thanked: 2 times
Re: Order Edit: Extract name and country from delivery address
Thanks to @zipurman who coded for me a hook with 24 lines of js. It is kind of tricky, though, as the "ship to" address is just a block of text separated by line breaks. Anyway, it's perfectly working!Kofod95 wrote: ↑Sun Jan 29, 2023 7:18 am I wish you good luck!
If you get stuck, I think I could be a little more helpful, and maybe others know better than me - as a PRO-Supporter you have of course also the option to post in the VIP-forum to get expert advice from core coders, should we fail to solve things here. So at least there is a fallback;)
-anyway, I look forward to hear of your progress!
//Daniel
Cheers, Eddy