Hey!
It’s a great idea, which ideally should be implemented with a sophisticated visual editor. Similar to some page builders, providing smart fields to select any meta data to display. Maybe even scanning 3rd party custom fields (meta data) plugins.
Like Elementor‘s “Dynamic Tags” (a.k.a Dynamic Content), which draws content from the website, or from the current page/post, changing dynamically according to the Page or Post it’s on. Given a rich “PowerPoint“-like visual editor, you would add a dynamic data box where you need them, or inline text tag, to render some meta data.
Creating such an editor would require very sophisticated client code in React or Angular, to make it right. So, it’s pretty complicated.
But, for specific needs, you can (relatively) easily modify this simple plugin. I bothered to document pretty much every code block there is, so it’s easier to understand. For others and for me supporting the plugin in the future, forgetting how it works every single time:)
Here are the areas you’ll probably add your functionality to:
In the plugin /admin folder there is an admin.php file with the label page generation function:
function generate_shipping_labels_page_html( $orders ) {...}
it’s the AJAX function generating the page of labels on the server, which you then get to print in the new opened tab.
In that function, there is a foreach loop, to get the orders objects from WooCommerce database:
foreach ($orders as $order_id) {...}
that’s where you can use the current $order_id or the $order object to get the order client meta data you need, from wherever you’re storing it.
The label HTML layout is generated in the switch statement, based on the saved layout name in the plugin settings:
switch ( $this->settings['recipient_details_layout'] ) {...}
There you can either modify an existing layout, or add your own.
If you add your own, add the corresponding layout option to the settings page array of layout options to select:
public $recipient_details_layout_options = array(...);
To adjust or add CSS, just search some fields classes to find where they are in the code. Most of the label CSS is using flexboxes, so fields are dynamically spread evenly, in case some don’t exist (like phone or country name, based on plugin settings).
Contact me directly via Facebook if you get stuck on something. It will be easier for me to send screenshots to explain.