• Resolved devflashmarketing

    (@devflashmarketing)


    Hi Support ??

    i have created a custom meta field that are displayed under every produkt in the admin ordre backend. This field is for comments for the team reading the order when its processed. So i dont need it to be shown in the PDF invoice.

    Do you have any hooks or anything to unset the meta or something before its added to the invoice?

    i tried something like this, but its not working for me.

    add_filter('wpo_wcpdf_document_item_data', 'remove_order_line_comment_from_pdf', 20, 2);
    function remove_order_line_comment_from_pdf($item_data, $item) {
    // Find og fjern 'order_line_comment' fra item_data
    foreach ($item_data as $key => $value) {
    if ($key === 'order_line_comment') {
    unset($item_data[$key]);
    }
    }
    return $item_data;
    }

    The customfield is created using this:

    add_action( 'woocommerce_after_order_itemmeta', 'add_comment_field_below_order_item', 10, 3 );
    function add_comment_field_below_order_item( $item_id, $item, $product ) {
    echo '<p><strong>Kommentar til driftsrapport:</strong></p>';
    echo '<textarea name="order_line_comment[' . $item_id . ']" style="width:100%;" rows="2">' . esc_textarea( $item->get_meta( 'order_line_comment', true ) ) . '</textarea>';
    }

    add_action( 'woocommerce_saved_order_items', 'save_order_item_comment', 10, 2 );
    function save_order_item_comment( $order_id, $items ) {
    if ( isset( $_POST['order_line_comment'] ) ) {
    foreach ( $_POST['order_line_comment'] as $item_id => $comment ) {
    wc_update_order_item_meta( $item_id, 'order_line_comment', sanitize_text_field( $comment ) );
    }
    }
    }

    add_filter( 'woocommerce_order_item_display_meta_key', 'display_order_item_comment_in_admin', 20, 3 );
    function display_order_item_comment_in_admin( $display_key, $meta, $item ) {
    if ( $meta->key === 'order_line_comment' ) {
    $display_key = 'Kommentar';
    }
    return $display_key;
    }

    How you can poke me in the correct way.

    The page I need help with: [log in to see the link]

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

    (@dwpriv)

    You can hide it with CSS. Try this code snippet

    /**
    * Hide custom field on invoice
    */
    add_action( 'wpo_wcpdf_custom_styles', function( $document_type, $document ) {
    if ( $order = $document->order && $document_type == 'proforma' ) {
    ?>
    .invoice .your-custom-meta-key {
    display: none;
    }
    <?php
    }
    }, 10 , 2 );

    Be sure to replace the your-custom-meta-key with the CSS selector of the custom field. You can use this guide to find the CSS selector.

    Thread Starter devflashmarketing

    (@devflashmarketing)

    Hi, and thanks for the answer. ??

    I did change my code to include a CSS class, and it is shown in the pdf if i show it with HTML and do an inspect as you instructed.

    But, i cant get it to target the css with the snippet you sendt me. it doesnt matter what css class i choose in your snippet it has no effect on the pdf. Is it because i have the Pro version?

    i even tried this:

    add_action( 'wpo_wcpdf_custom_styles', function( $document_type, $document ) {
    if ( $order = $document->order && $document_type == 'proforma' ) {
    ?>
    .invoice {
    display: none !important;
    }
    <?php
    }
    }, 10 , 2 );
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @devflashmarketing,

    It seems likely that you are not targeting the correct selector. However, since you are using the Professional extension, we’d be happy to assist you further with this, even looking to the HTML code ourselves. However, we’ll need to continue the conversation through our premium support channel at [email protected], as www.remarpro.com does not allow support for premium products here.

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