• Resolved nehadaga3

    (@nehadaga3)


    I want to add a custom field to invoice , this field is a product meta field.
    I am not a PHP coder but I tried to replicate the code which was coded for SKU field in invoice.php file inside plugin folder. can you please guide step by step on how to add a field. I was able to see the additional label added but the value for it was blank.what is the way to get the value for it. I am looking to add HSN_PROD_ID meta fields.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @nehadaga3

    You could add a custom field easily with our Premium Templates extension within a “Custom Field (Product)” column, like below:

    Captura-de-ecr-de-2020-08-11-10-59-41

    Alternatively you could use an action hook following this documentation page: Displaying product custom fields

    Hope that helps!

    Thread Starter nehadaga3

    (@nehadaga3)

    Thanks! But I have few more follow questions on the options I am trying to get through this. Is there any call support for wordpress where I can share my screen and get the issue resolved ?

    Plugin Contributor Ewout

    (@pomegranate)

    Because this is a free plugin, we can only provide limited support. If you decide to purchase the Premium Templates extension and need more help with the “Custom Field (Product)” column, we can always provide email support and screen sharing if necessary.

    Thread Starter nehadaga3

    (@nehadaga3)

    Thanks for the response! I created a child theme and then created the custom template under it.I referred below link to add custom field.
    https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-a-custom-field/

    Below is the piece of code i added to test:
    I do see the label ‘delivery-date’ in my invoice but the value is blank.
    I tried with different meta_keys to test if this code works but value is not being displayed for any of it.
    add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_delivery_date’, 10, 2 );
    function wpo_wcpdf_delivery_date ($template_type, $order) {

    ?>
    <tr class=”delivery-date”>
    <th>Delivery Date:</th>
    <td><?php echo $order->get_meta(‘_qty’); ?></td>
    </tr>
    <?php

    }

    quesitons:
    1. I used this table to get the meta_key name -SELECT disitnct meta_key FROM wp_woocommerce_order_itemmeta –> Is this right ?
    My product dashboard has HSN Code a field but where can i find meta_key for it ?

    2. In which file the functions get_meta() or get_order_items() can be found to see what the code is and what it is returning ? (does it stores only specific values which are displayed in ‘Simple’ template. )

    3. can you please guide through the steps on how to fetch the value .

    Plugin Contributor Ewout

    (@pomegranate)

    I think you took the wrong documentation page (about order meta), you need the one linked by Alex in the post above (about product meta):
    Displaying product custom fields

    1. You can use Store Toolkit for WooCommerce to see order/item/product meta directly in the backend.
    2. The functions you used are core WooCommerce functions, you can find the source code on github
    3. If you need more help with this after having read the above instructions, I recommend hiring a PHP developer for this (or using our Premium Templates extension for a no-code solution). Do note that there is a difference between order meta ($order->get_meta('META_KEY')), order item meta (wc_get_order_item_meta($item_id, 'MEYA_KEY')) and product meta ($product->get_meta('MEYA_KEY'))
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding custom field’ is closed to new replies.