• Resolved roberto22

    (@roberto22)


    Hi,

    I am using this plugin “Ni WooCommerce Sales Report By User Role” to link sales to our sales agent.

    Is it possible to print the sales agent name in the invoice? The user role is “Ni Sales Agent”

    thanks for the help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter roberto22

    (@roberto22)

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @roberto22,

    It’s likely that the sales agent is stored in the order metadata, like a custom field/metadata, you just need to figure out its name. If you don’t know the name of your custom field, see Finding WooCommerce custom fields

    You can add custom fields to your invoices using the template action hooks. See several examples about adding new fields to your invoices here.

    Let’s say your custom field is stored with the order meta key sales_agent, then you could add this field to your invoices using the following code snippet:

    
    /**
     * Display sales agent after order data on the packing slip
     */
    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_sales_agent', 10, 2 );
    function wpo_wcpdf_sales_agent($template_type, $order) {
    	if ($template_type == 'invoice') {
    		if( $sales_agent = $order->get_meta('sales_agent')) {
    			?>
    			<tr class="sales-agent">
    			<td>Sales agent:</td>
    			<td><?php echo $sales_agent; ?></td>
    			</tr>
    			<?php						
    		}
    	}
    }
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    You can also add any field, without no code, using Premium Templates. This extension includes a customizer that allows you to tailor your PDF documents using product columns, total rows, and custom blocks. In addition, Premium Templates provides two additional templates: Business and Modern.

    For your specific case, you only need to add a custom, block this way:

    A screenshot that display an use example of the custom blocks

    Then, your invoices will display your custom field:

    A screenshot that display the example custom field on the invoice

    Let me know if you have more questions ??

    Thread Starter roberto22

    (@roberto22)

    Hi,

    Thanks a lot for the help. I am using the snippet wioth the metadata but it shows the id and not the name https://prnt.sc/1xrlm5zhttps://prnt.sc/1xrlqkh

    I did installed the plugin to see all the custom fields hidden but there isnt one to display the name.

    Is there a way you can help me print the name instead of the number id.

    Thanks!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi Roberto,

    Please replace my previous code snippet for this one:

    /**
     * Display sales agent after order data on the invoice
     */
    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_sales_agent', 10, 2 );
    function wpo_wcpdf_sales_agent($template_type, $order) {
    	if ($template_type == 'invoice') {
    		if( $sales_agent_id = $order->get_meta('_ic_sales_agent_user_id')) {
    			$sales_agent_data = get_userdata( $sales_agent_id );
    			$sales_agent_full_name = $sales_agent_data->first_name . ' ' . $sales_agent_data->last_name;
    			?>
    			<tr class="sales-agent">
    			<td>Sales agent:</td>
    			<td><?php echo $sales_agent_full_name; ?></td>
    			</tr>
    			<?php						
    		}
    	}
    }

    Let me know if it worked ??

    Thread Starter roberto22

    (@roberto22)

    Hi,

    Yes, it worked.

    Thank you for thr awesome support ??

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m happy to know that it worked!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add custom information to invoice’ is closed to new replies.