• Resolved kingbolo

    (@kingbolo)


    Hi,
    Thanks to the explanation on your website how to add a custom field I got a VAT number (the custom field) to show on the invoice. (used the template action hook for a delivery date near the bottom – second to last ). Thank you for that.

    How would I change this that so that the custom field only is shown when a value is entered in the check-out proces.
    So if a company is ordering and adds a VAT number only in that case the custom fields and the preceding text is shown.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor dwpriv

    (@dwpriv)

    You could use an if statement to show the field if it is not empty

    Thread Starter kingbolo

    (@kingbolo)

    Thank you for your reply.

    Yeas an If statement is possible. Just don’t know how to get that right.
    The custom field is _billing_vat_number and generated by the plugin Woo EU VAT Number.
    I have :

    function cust_vat_number ($template_type, $order) {
    if ($template_type == ‘invoice’) {
    $document = wcpdf_get_document( $template_type, $order );
    ?>
    Uw BTW nummer custom_field(‘_billing_vat_number’); ?>
    <?php
    }
    }

    $vat = get_post_meta( $post->ID, ‘_billing_vat_number’, true );
    if( isset( $vat ) ){
    add_action( ‘wpo_wcpdf_after_order_data’, ‘cust_vat_number’, 10, 2 );
    }

    But this shows the preceding text in all cases. So also when an VAT number is not entered.

    Plugin Contributor dwpriv

    (@dwpriv)

    Give this snippet a try

    add_action( 'wpo_wcpdf_after_order_data', 'cust_vat_number', 10, 2 );
    function cust_vat_number( $template_type, $order ) {
    if ( $template_type == 'invoice' ) {
    $custom_field = $order->get_meta( '_billing_vat_number' );
    if ( ! empty( $custom_field ) ) {
    ?>
    Uw BTW nummer <?php echo $custom_field; ?>
    <?php
    }
    }
    }
    Thread Starter kingbolo

    (@kingbolo)

    Hi,
    Sorry, for the late reply. Totally missed your post.
    Thank you, will try this.

    Thread Starter kingbolo

    (@kingbolo)

    Hi dwpriv

    With a slight adjustment it works.
    I had to replace

    Uw BTW nummer <?php echo $custom_field; ?>

    With

    <tr class="vat-nummer">
    <th>Uw BTW nummer</th>
    <td><?php echo $custom_field; ?> </td>
    </tr>

    That did the trick.
    Thank you for your help.

    Plugin Contributor dwpriv

    (@dwpriv)

    No problem, @kingbolo. I’ll mark this topic as resolved. Feel free to open another thread if you need help with something else.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.