• Resolved christianguevara

    (@christianguevara)


    Hello,

    I use plugin Checkout Form, I try to print with your plugin my customs fields.
    I follow instrucction in your documentation but it’s doesn’t works the code that I put.

    This is the code

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date', 10, 2 );
    function wpo_wcpdf_delivery_date ($document_type, $order) {
        $document = wcpdf_get_document( $document_type, $order );
        if ($document_type == 'packing-slip') {
            ?>
            <tr class="franja_horaria_semana">
                <th>Delivery Date:</th>
                <td><?php $document->custom_field('franja_horaria_semana'); ?></td>
            </tr>
            <?php
        }

    I used the plugin store toolkit to make sure that the name of the meta was correct, in the toolkit it registers it as franja_horaria_semana, which is the name I give it in the checkout form module, I don’t know what I’m doing wrong.

    Can you help me?

    thank you
    Christian`

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @christianguevara,

    The reason why your code is not displayed on the invoice is because you’re adding a check ($document_type == 'packing-slip') that limit the code to be displayed only on the packing slip.

    However, this is an improved version of your code snippet that will display your custom field on the invoice only if present:

    /**
     * Add the Delivery Date on the invoice
     */
    add_action( 'wpo_wcpdf_after_order_data', function ($document_type, $order ) {	
    	if ( $document_type == 'invoice' ) {
    		if ( $delivery_date = $order->get_meta( 'franja_horaria_semana' ) ) {
    			?>
    			<tr class="franja_horaria_semana">
    			<th>Delivery Date:</th>
    			<td><?php echo $delivery_date; ?></td>
    			</tr>
    			<?php
    		}
    	}
    }, 10, 2 );

    If you prefer to display your custom field in both invoice and packing slip, use this code snippet instead:

    /**
     * Add the Delivery Date on the invoice and packing slip
     */
    add_action( 'wpo_wcpdf_after_order_data', function ($document_type, $order ) {
    if ( $delivery_date = $order->get_meta( 'franja_horaria_semana' ) ) {
    		?>
    		<tr class="franja_horaria_semana">
    		<th>Delivery Date:</th>
    		<td><?php echo $delivery_date; ?></td>
    		</tr>
    		<?php
    	}
    }, 10, 2 );

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

    Let me know if it worked!

    Thread Starter christianguevara

    (@christianguevara)

    Ohhh, A lot of Thanks Yordan, I’ts works ??

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that it worked, @christianguevara!

    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!

    Thread Starter christianguevara

    (@christianguevara)

    Done ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘I can’t add customs fields in my invoice’ is closed to new replies.