• Resolved bluelee22

    (@bluelee22)


    Hi,
    
    I'm using this plugin to add custom fields "WooCommerce Checkout Manager" and I've added to the checkout billing fields a few custom fields that show the name of the company, company ID, and 2 other fields. I want those fields to be displayed in the Invoice, but the only output I'm getting is the Label, and the values are not shown.?
    
    All the custom fields are hidden until the answer to a previous question is yes, but in my testing the answer in the order was yes and all the custom fields were fulfilled. In that case I would like also to know if it's possible to hide those fields in the invoice if the answer is No or if the fields are empty.
    
    This is the code I'm using:
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_service_charge', 10, 2 );
    function wpo_wcpdf_service_charge ($template_type, $order) {
            ?>      
            <tr class="billing_wooccm13">
                <th>Company:</th>
                <td><?php $order->get_meta('billing_wooccm13'); ?></td>
            </tr>
            <?php
        
    }
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_service_charge', 10, 2 );
    function wpo_wcpdf_service_charge ($template_type, $order) {
            ?>      
            <tr class="billing_wooccm10">
                <th>Company ID:</th>
                <td><?php $order->get_meta('billing_wooccm10'); ?></td>
            </tr>
            <?php
        
    }
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_service_charge', 10, 2 );
    function wpo_wcpdf_service_charge ($template_type, $order) {
            ?>      
            <tr class="billing_wooccm11">
                <th>SSa:</th>
                <td><?php $order->get_meta('billing_wooccm11'); ?></td>
            </tr>
            <?php
        
    }
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_service_charge', 10, 2 );
    function wpo_wcpdf_service_charge ($template_type, $order) {
            ?>      
            <tr class="billing_wooccm12">
                <th>SSb:</th>
                <td><?php $order->get_meta('billing_wooccm12'); ?></td>
            </tr>
            <?php
        
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi, @bluelee22:

    I’m using this plugin to add custom fields “WooCommerce Checkout Manager” and I’ve added to the checkout billing fields a few custom fields that show the name of the company, company ID, and 2 other fields. I want those fields to be displayed in the Invoice, but the only output I’m getting is the Label, and the values are not shown.

    This is because you are not echoing the values, that is, you have to use echo before retrieving the values, like this:

    <td><?php echo $order->get_meta('billing_wooccm13'); ?></td>

    All the custom fields are hidden until the answer to a previous question is yes, but in my testing the answer in the order was yes and all the custom fields were fulfilled. In that case I would like also to know if it’s possible to hide those fields in the invoice if the answer is No or if the fields are empty.

    To achieve this, you have to add an extra check, like this:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_service_charge', 10, 2 );
    function wpo_wcpdf_service_charge ($template_type, $order) {
        if ( ! empty( $order->get_meta('billing_wooccm13') ) ) {
            ?>      
            <tr class="billing_wooccm13">
                <th>Company:</th>
                <td><?php echo $order->get_meta('billing_wooccm13'); ?></td>
            </tr>
            <?php
        }
    }
    Thread Starter bluelee22

    (@bluelee22)

    Thanks for the great support!

    It did not work at first but I figured out that the meta key was incorrect, but everything else is flawless!!

    Thanks again.

    • This reply was modified 2 years, 1 month ago by bluelee22.
    • This reply was modified 2 years, 1 month ago by bluelee22.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m glad to hear that it is working now, @bluelee22! ??

    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 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add custom field to invoice’ is closed to new replies.