• Resolved linux4me2

    (@linux4me2)


    I have a product that includes two custom order item meta entries: “configuration” and “image,” both of which currently show up on invoices and packing slips.

    The value of the “image” custom order item meta is used in the filter wpo_wcpdf_after_item_meta to add an image to the invoice/packing slip, so I need its value available in that function, but I don’t want to display the “image” custom order item meta itself in the invoice/packing slip.

    Is there a way to prevent the “image” custom order item meta from showing up on the invoice, and still have it available to wpo_wcpdf_after_item_meta?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter linux4me2

    (@linux4me2)

    I think I have it figured out, or at least one solution that works for me.

    In case anyone else wants to prevent a custom order item meta from appearing in an invoice and packing slip, you can add the following code snippet to your child theme’s functions.php:

    
    add_filter('woocommerce_order_item_get_formatted_meta_data', 'unset_specific_order_item_meta_data', 10, 2);
    function unset_specific_order_item_meta_data($formatted_meta, $item){
        /*
        // Only on emails notifications
        if(is_admin() || is_wc_endpoint_url()) {
            return $formatted_meta;
        }
        */
    
        foreach($formatted_meta as $key => $meta){
            if(in_array($meta->key, array('<name of your order item meta to remove>'))) {
                unset($formatted_meta[$key]);
            }
        }
        return $formatted_meta;
    }
    

    Just replace <name of your order item meta to remove> with a comma-separated list (in single quotes) of the order item meta(s) names you want to remove. This is a WordPress function, and will also remove the order item meta from notification emails.

    If you want the order item meta to appear in admin-generated PDF invoices and admin email notifications, you can try un-commenting this section:

    
    if(is_admin() || is_wc_endpoint_url()) {
        return $formatted_meta;
    }
    

    I haven’t tested that part, because I wanted the item meta hidden everywhere.

    Using this solution is perfect for my needs, because it doesn’t delete the custom order item meta name/value, it just doesn’t include them in the formatted output.

    I found the answer here, so thanks to LoicTheAztec.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide Custom Order Item Meta?’ is closed to new replies.