• Resolved emzdesign

    (@emzdesign)


    Hello

    I have added an Advanced Custom Field to my products page, and when an invoice is generated I want that Advanced Custom Field to display under the SKU of the product.

    I am using the following code:

    <?php $this->custom_field('_hs_code'); ?>

    I have tried with and without the underscore, but it doesn’t work either way.

    Am I missing something?

    Thanks,
    Emma

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

    (@alexmigf)

    Hello @emzdesign

    The $this is referring the document object, but you have the custom field saved in product meta.

    With our Premium Templates extension you can add it very easily inside the product column, this way you don’t need to mess with code:

    Captura-de-ecra-2020-06-01-a-s-17-23-54

    You shouldn’t make this changes directly on the core templates, because when you update the plugin you will loose them. If you decide to go with the code implementation i recommend you to use a custom template, and read this documentation page: Displaying product custom fields

    • This reply was modified 4 years, 9 months ago by alexmigf.
    Thread Starter emzdesign

    (@emzdesign)

    Hi

    Thanks for your help. I did look at that link earlier and have tried that way too, but it didn’t work either.

    The code I used was:

    <?php
    if (!empty($item['product'])) {
        // replace 'Location' with your custom field name!
        $field_name = 'hs_code';
        $hs_code = $item['product']->get_meta($field_name,true,'edit');
        if ( !empty($hs_code) ) {
            echo 'HS Code: '.$hs_code.'';
        }
    }
    ?>

    Am I missing something there? I am using a custom template as well. Thanks for your help.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @emzdesign

    Can you show me the ACF field screen?

    Thread Starter emzdesign

    (@emzdesign)

    Of course

    Thank you.

    Thread Starter emzdesign

    (@emzdesign)

    I’m not sure why but it says this issue is resolved but it isn’t. How can I change that?

    Plugin Contributor Ewout

    (@pomegranate)

    Code looks fine to me. Where in the template did you place this? Is this for variable products or for simple products? You could also try using the ACF the_field()/get_field() functions like so:

    
    <?php
    if( $hs_code = get_field( 'hs_code', $item['product_id'] ) ) {
    	echo 'HS Code: '.$hs_code;
    }
    ?>
    

    But note that this will only work properly inside the order items table.

    Thread Starter emzdesign

    (@emzdesign)

    I saw another post with a similar issue where you recommended the Store Toolkit. I installed that plugin and checked the order, and it appears the hs_code isn’t being passed through with the order?

    I suppose this is more of an ACF issue than an issue with the WooCommerce PDF Invoices & Packing Slips.

    I will get in touch with them to see if there’s a way around it then update this thread with (hopefully) a solution.

    Thread Starter emzdesign

    (@emzdesign)

    @pomegranate forget my last reply – that code you provided worked perfectly! Thank you so much!

    Plugin Contributor Ewout

    (@pomegranate)

    Glad to hear that @emzdesign !

    If you could spare a minute for a plugin review here on www.remarpro.com we’d greatly appreciate it.

    All the best with your store and have a fantastic day!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding Advanced Custom Field to Invoice’ is closed to new replies.