• Resolved holle75

    (@holle75)


    Hi, i would like to print the standard product-field “HS/HSN Code” for each of the products on the packing-slip.

    Thank you for any advice

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

    (@yordansoares)

    Hi @holle75,

    You can use the PDF template action hooks, e.g. wpo_wcpdf_after_item_meta, like this:

    /**
    * WooCommerce PDF Invoices & Packing Slips:
    * Display HS/HSN Code after item meta (if not empty)
    */
    add_action( 'wpo_wcpdf_after_item_meta', function( $document_type, $item, $order ) {
    if ( isset( $item['product'] ) ) {
    // Change 'hs_code' with the actual meta key in the next line
    if ( $value = $item['product']->get_meta( 'hs_code' ) ) {
    echo "<div class=\"hs-code\"><small>HS/HSN Code: {$value}</small></div>";
    }
    }
    }, 10, 3 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use code snippets. We also have a blog post here that you may find helpful about adding custom code to your site.

    Please note that if you have the customizer, included in the PDF Invoices and Packing Slips Plus Bundle, you can use the Custom field block instead of the code snippet I shared above:

    Thread Starter holle75

    (@holle75)

    Hi Yordan, much appreciated!

    Plugin Contributor Yordan Soares

    (@yordansoares)

    We are always happy to help, @holle75! 🙂

    By the way, 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 holle75

    (@holle75)

    I will! (or i did? …. i have to check)

    Besides that, i´m not succesful with the code. I don´t know if this field is “not a meta field” or if “variable products” create confusion.

    The fields are implemented by germanized -> https://de.ww.wp.xz.cn/plugins/woocommerce-germanized/

    and are part of the tab delivery in products. I did ask the programmer what the meta field name is -> “_hs_code” ….. but no luck.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m not familiar with that plugin, but it sounds to me like a product custom field. However, if the code above does not work, I would ask them how they store this value in the shop (and which meta key they use to do it!), to try to help you further 🙂

    Please note that there are several kinds of fields:

    • Order fields
    • Refund fields (this is a separated set of data, treated as a type of “order”)
    • Product fields
    • Item fields

    Types 3 and 4 should be the ones used by a data such as HS/HSN code, as this seems to be related with the product as such.

    Thread Starter holle75

    (@holle75)

    let me ask in the other thread what type of field this is …. i´ll get back

    (the name of the field is “_hs_code”)

    thanks!

    Thread Starter holle75

    (@holle75)

    Hi Yordan. i got the information that “_hs_code” is a product meta-field. It seems to me that your provided code for functions.php should specifically work on products. Any ideas why not?

    thank you

    Thread Starter holle75

    (@holle75)

    —- this works for the short descripion in the packing slip on my setup as an example and is attached to product fields

    add_action( ‘wpo_wcpdf_after_item_meta’, ‘wpo_wcpdf_show_product_description’, 10, 3 );
    function wpo_wcpdf_show_product_description ( $template_type, $item, $order ) {
    if (empty($item[‘product’])) return;
    if ( $template_type == ‘packing-slip’) {
    $_product = $item[‘product’]->is_type( ‘variation’ ) ? wc_get_product( $item[‘product’]->get_parent_id() ) : $item[‘product’];
    if ( method_exists( $_product, ‘get_short_description’ ) ) {
    $description = $_product->get_short_description();
    printf(‘

    %s’, $description );
    }
    }
    }

    (mmh, inline code markup doesn´t work)

    • This reply was modified 1 year, 2 months ago by Jan Dembowski. Reason: Formatting
    • This reply was modified 1 year, 2 months ago by Jan Dembowski.
    Thread Starter holle75

    (@holle75)

    Hi, any news on this challenge? Why is this marked as resolved?

    Plugin Contributor dwpriv

    (@dwpriv)

    @holle75 apologies for the delayed response.

    The code seems fine to me. Is the custom field still not being printed?

    Thread Starter holle75

    (@holle75)

    Hi, this works for the short descripion of a product and is just an example that the principle works. I´m looking for the equivalent for the HS-Code meta-field

    Plugin Contributor dwpriv

    (@dwpriv)

    @holle75

    I see. You can try this updated snippet Yordan shared earlier with the updated _hs_code meta key

    /**

     * WooCommerce PDF Invoices & Packing Slips:

     * Display HS/HSN Code after item meta (if not empty)

     */

    add_action( 'wpo_wcpdf_after_item_meta', function( $document_type, $item, $order ) {

        if ( isset( $item['product'] ) ) {

            // '_hs_code' is the actual meta key

            if ( $value = $item['product']->get_meta( '_hs_code' ) ) {

                echo "<div class=\"hs-code\"><small>HS/HSN Code: {$value}</small></div>";

            }

        }

    }, 10, 3 );
    Thread Starter holle75

    (@holle75)

    Hi, and thank you for taking care of my question. I tried with the new code without luck.

    I checked the database and could find the meta _hs_code in table

    wp_postmeta

    meta_id post_id meta_key meta_value
    15468 2013 _hs_code 76130000

    Does this info ring any bells for you?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @holle75,

    The code snippet that Delano shared with you should work. Could you please tell us where are you placing the code, or how are you activating it?

    Thread Starter holle75

    (@holle75)

    Hi Yordan, i implemented the code in functions.php of the used child theme.

    The formerly shared code for the short description is (still) working. Thats why i´m irritated. I want to emphasize again, that those products are variable products (if there is any difference).

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘HS/HSN Code on packing-slip’ is closed to new replies.