Support » Plugin: Checkout Field Manager (Checkout Manager) for WooCommerce » Custom Additional Checkout Field Not Adding to PDF invoice using code snippet

  • Resolved abgross1

    (@abgross1)


    Hello. I’m using this plugin on my site, https://carsonscookiefix.com, along with the Woocommerce PDF Invoice & Packing Slips plugin (https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/). I’m trying to add the Checkout Manager additional fields to my pdf invoice using code snippets. I’ll begin by saying I’ve spent hours trying to troubleshoot this myself and searching the forums. Nothing I found worked. Also, I want to mention that this previously worked and it was just recently where it stopped working. It looks like the code in the invoice.php file changed which must have caused the issue. Previously, the below code snippet worked when added to the invoice.php file located in /wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple:

    <?php $wpo_wcpdf->custom_field(‘myfield3’, ‘Order Notes:’); ?>

    (I added this after the after_order_details section in the php file)

    It seems as though the code changed per the documentation found in this link (https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-a-custom-field/), and so the below code snippet is now what should be added:

    <?php $this->custom_field(‘myfield3’, ‘Order Notes:’); ?>

    This does not work. I tried adding it to the invoice.php file within the plugin files and also by creating a custom template in my child theme folder, as well as the main theme folder. Nothing worked. I enabled the debug output, and this is the notice I get in the PDF:

    Notice: Use of undefined constant ‘myfield3’ – assumed ‘‘myfield3’’
    in /www/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple/invoice.php on line 139

    I tried adding simple text “test” in place of the snippet and the output worked fine. So it seems as though it does not like the html I am adding.

    Please note, I also attempted the below snippets which also did not work:
    <?php $this->custom_field(‘_myfield3’, ‘Order Notes:’); ?>
    <?php $this->custom_field(‘myfield3’); ?>
    <?php $this->custom_field(‘additional_myfield3’, ‘Order Notes:’); ?>
    <?php $this->custom_field(‘_additional_myfield3’, ‘Order Notes:’); ?>
    <?php $this->custom_field(‘_billing_myfield3’, ‘Order Notes:’); ?>
    <?php custom_field(‘myfield3’); ?>
    <?php $this->custom_field(‘_custom_myfield3’); ?>
    <?php $this->custom_field(‘custom_myfield3’); ?>

    I probably tried more than that but that’s all I can remember. I tried them all within the plugin and theme files.

    I also installed the plugin Woocommerce Store Toolkit (https://wordpress.org/plugins/woocommerce-store-toolkit/) to ensure I was using the right custom field meta tag. It confirmed that the meta tag should simply be “myfield3”.

    I’m using all current versions of my theme, WordPress, plugins, and WooCommerce. My memory limit is set at 256M.

    What am I missing? I don’t understand why it was working previously and now it isn’t. Thank you in advance for your help.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • @abgross1: you have very beautiful website, by the way did you manage to resolve the issue? i’m facing same issue with pdf invoices.

    same here…

    oh wait I managed to make it work!

    Check the below code where i cloned the <div class=”billing-phone”> and then add the rest: <?php $this->custom_field('myfield1', 'P.IVA/C.F.:'); ?></div>

    		<td class="address billing-address">
    			<!-- <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
    			<?php $this->billing_address(); ?>
    			<?php if ( isset($this->settings['display_email']) ) { ?>
    			<div class="billing-email"><?php $this->billing_email(); ?></div>
    			<?php } ?>
    			<?php if ( isset($this->settings['display_phone']) ) { ?>
    			<div class="billing-phone"><?php $this->billing_phone(); ?></div>
    			<?php } ?>
    			<div class="billing-phone"><?php $this->custom_field('myfield1', 'P.IVA/C.F.:'); ?></div>
    		</td>

    It’s working for me, hope the same for you!
    bye

    • This reply was modified 6 years, 1 month ago by marcobeccari.

    Hi Marco,

    I have the same issue. I need to display “myfield1″ (P.iva) in my invoices.

    did you add the code you mentioned in invoice.php? So do I need to add this at the end of the page?

    <?php $this->custom_field(‘myfield1’, ‘P.IVA/C.F.:’); ?></div>

    <td class=”address billing-address”>
    <!– <h3><?php _e( ‘Billing Address:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></h3> –>
    <?php $this->billing_address(); ?>
    <?php if ( isset($this->settings[‘display_email’]) ) { ?>
    <div class=”billing-email”><?php $this->billing_email(); ?></div>
    <?php } ?>
    <?php if ( isset($this->settings[‘display_phone’]) ) { ?>
    <div class=”billing-phone”><?php $this->billing_phone(); ?></div>
    <?php } ?>
    <div class=”billing-phone”><?php $this->custom_field(‘myfield1’, ‘P.IVA/C.F.:’); ?></div>
    </td>

    Hi Diana,
    Yes the file I edited is invoice.php and the code goes right after the DIV billing address (doing so you have the p.iva/c.f. value just below the other customer’s info when the Pdf is rendered).

    Hi Marco,

    ok I added this:

    <div class=”billing-phone”><?php $this->custom_field(‘myfield5’, ‘P.IVA/C.F.:’); ?></div>

    just after this:

    <div class=”billing-phone”><?php $this->billing_phone(); ?></div>
    <?php } ?>

    …but it doesn’t still work 🙁

    ciao Diana,
    I assume you are editing the invoice.php inside of /wp-content/themes/mystile/woocommerce/pdf/”yourtemplatename”/invoice.php (where “yourtemplatename” is the name you specified for your custom template in the plugin interface).
    Anyway, better if I send you all the code from the opening <table>

    <table class="order-data-addresses">
    	<tr>
    		<td class="address billing-address">
    			<!-- <h3><?php _e( 'Billing Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3> -->
    			<?php $this->billing_address(); ?>
    			<?php if ( isset($this->settings['display_email']) ) { ?>
    			<div class="billing-email"><?php $this->billing_email(); ?></div>
    			<?php } ?>
    			<?php if ( isset($this->settings['display_phone']) ) { ?>
    			<div class="billing-phone"><?php $this->billing_phone(); ?></div>
    			<?php } ?>
    			<!--AGGIUNTA Codice Fiscale o P. Iva -->
    			<div class="billing-phone"><?php $this->custom_field('myfield1', 'P.IVA/C.F.:'); ?></div>
    			<!--END-->
    			<!--AGGIUNTA Gender Selection -->
    			<div class="billing-phone"><?php $this->custom_field('myfield2', 'Sesso/Gender:'); ?></div>
    			<!--END-->
    		</td>
    		<td class="address shipping-address">
    			<?php if ( isset($this->settings['display_shipping_address']) && $this->ships_to_different_address()) { ?>
    			<h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
    			<?php $this->shipping_address(); ?>
    			<?php } ?>
    		</td>
    		<td class="order-data">
    			<table>
    				<?php do_action( 'wpo_wcpdf_before_order_data', $this->type, $this->order ); ?>
    				<?php if ( isset($this->settings['display_number']) ) { ?>
    				<tr class="invoice-number">
    					<th><?php _e( 'Invoice Number:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->invoice_number(); ?></td>
    				</tr>
    				<?php } ?>
    				<?php if ( isset($this->settings['display_date']) ) { ?>
    				<tr class="invoice-date">
    					<th><?php _e( 'Invoice Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->invoice_date(); ?></td>
    				</tr>
    				<?php } ?>
    				<tr class="order-number">
    					<th><?php _e( 'Order Number:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->order_number(); ?></td>
    				</tr>
    				<tr class="order-date">
    					<th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->order_date(); ?></td>
    				</tr>
    				<tr class="payment-method">
    					<th><?php _e( 'Payment Method:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<td><?php $this->payment_method(); ?></td>
    				</tr>
    				<?php do_action( 'wpo_wcpdf_after_order_data', $this->type, $this->order ); ?>
    			</table>			
    		</td>
    	</tr>
    </table>

    Ciao Marco,

    actually I’m modifying invoice.php in:
    wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple
    (I don’t have woocommerce folder in my Theme folder, but only woocommerce.php).

    I replaced the code you wrote, replacing only the number of my field “myfield5” instead of “myfield1” but I still can’t see the P.IVA in invoices. That’s annoying and I don’t know what to do solve this :-/ Mi potresti lasciare la tua email?

    maurizio

    (@maurizioercole)

    Helo!
    If your field is in billing section use this string:

    <?php $this->custom_field(‘billing_field-name’, ‘Label:’, true); ?>

    The trick is to add billing_ before the name of field. So if I have a field name like “piva”, the field name in this string is: billing_piva

    Instead if your filed is a additional field (custom field) use this one:

    <?php $this->custom_field(‘field-name’, ”); ?>
    or
    <?php $this->custom_field(‘field-name’, ‘Label:’, true); ?>

    In this case the name of field is the real name.

    hope that is useful for you 😀
    Bye

    • This reply was modified 5 years, 4 months ago by maurizio.
    • This reply was modified 5 years, 4 months ago by maurizio.
    • This reply was modified 5 years, 4 months ago by maurizio.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom Additional Checkout Field Not Adding to PDF invoice using code snippet’ is closed to new replies.