add_filter('woocommerce_formatted_address_replacements', 'woocommerce_formatted_address_replacements', 10, 2);
function woocommerce_formatted_address_replacements($replacements, $args) {
$replacements['{name}'] = $args['last_name']. ' ' . $args['first_name'];
return $replacements;
}
Try using the code snippet in the active theme functions.php file
Hello and thanks for your answer.
I’m just waiting for a new order to see if it works.
Regards
Hi @yodastudio,
The WooCommerce platform does not support the reversal of the customer’s first and last name in the shipping and billing addresses directly in the settings. This can only be achieved through the help of a custom code or a third-party plugin.
I’m just waiting for a new order to see if it works.
However, to test any custom coding like the one shared above, it is recommended to first make the test from a staging site before implementing it on any live store.
I hope this helps.
Hello there!
The provided code doesn’t seem to work, I’ll keep on looking for a plugin.
Regards.
Hi @yodastudio,
The provided code doesn’t seem to work, I’ll keep on looking for a plugin.
Thank you for sharing an update on this.
You can try running the exact question you’re asking, along with the code provided, through an AI platform like ChatGPT for recommendations/changes to your code.
I hope this helps.
We got it!
add_filter('woocommerce_formatted_address_replacements', 'custom_formatted_address_replacements', 10, 2);
function custom_formatted_address_replacements($replacements, $args) {
if (isset($args['first_name']) && isset($args['last_name'])) {
$replacements['{name}'] = $args['last_name'] . ' ' . $args['first_name'];
}
return $replacements;
}
And it works! Thanks to ChatGPT.
Hi @yodastudio,
I’m glad you tried out our suggestions on using ChatGPT and the suggested code worked for you!
If you have a few minutes, we’d love if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/
Cheers!