Add Username in Invoice
-
Hello everyone and happy year!
I need to add the username in the invoice and in the praise. Can anybody help me?
Thanks in advance
The page I need help with: [log in to see the link]
-
Hi! Here’s some documentation that may help:
Displaying user dataFor the username specifically:
<?php if ( $user = $this->order->get_user() ) { echo 'Username: ' . $user->user_login . '<br />'; } ?>or as an action hook, adding the username after the order data:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_order_username', 10, 2 ); function wpo_wcpdf_order_username ($template_type, $order) { if ( $user = $this->order->get_user() ) { ?> <tr class="custom-user-login"> <th>Username:</th> <td><?php echo $user->user_login; ?></td> </tr> <?php } }Hope that helps!
EwoutThank you very much for the help!
I just bought the Premium plugim. I do not know if there is a special forum for users who have purchased the payment supplement so I ask you again on this ticket.
I do not know if I acted correctly but I added the second code that you gave me to the functions file but it gave me an error:
Fatal error: Using $ this when not in object context in /usr/home/vegan-tattoo.com/web/wp-content/themes/DiviChildTheme/functions.php on line 358
1) Can you tell me where exactly I have to add the code?
2) Before the purchase of the Premium version had installed the free version of the plugin. Do I have to delete the free version?
Nor do I see the customizer or the Premium templates.
Hi! I will answer your questions about the premium templates in an email, as we’re not allowed to use these forums for paid support.
There was an error in the code snippet, this should work:add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_order_username', 10, 2 ); function wpo_wcpdf_order_username ($template_type, $order) { if ( $user = $order->get_user() ) { ?> <tr class="custom-user-login"> <th>Username:</th> <td><?php echo $user->user_login; ?></td> </tr> <?php } }Great! Now the code worked.
Is it possible to add the Text at the top in the column on the left (Customer Data)?yes, you can use another action hook for that,
wpo_wcpdf_after_document_labelinstead ofwpo_wcpdf_after_order_data:add_action( 'wpo_wcpdf_after_document_label', 'wpo_wcpdf_order_username', 10, 2 ); function wpo_wcpdf_order_username ($template_type, $order) { if ( $user = $order->get_user() ) { ?> <div class="custom-user-login">Username: <?php echo $user->user_login; ?></div> <?php } }It worked! A great job. Thank you very much.
Is it possible to make some CSS or other type changes to modify the appearance?
Specifically:
In the column on the right where the order data are, I would like to increase the width so that there are no line breaks and each text data occupies a line.Sure! With custom CSS:
td.order-data { width: 50%; }Do note that this decreases the space for the shipping address on the invoice (if you have enabled that setting), normally it’s 2 * 30% for the billing and shipping address side by side.
Ewout
Great!
It has worked perfectly!
Thank you very much!
The topic ‘Add Username in Invoice’ is closed to new replies.