• Resolved druut

    (@emkemk)


    Hello, I’m trying to remove specific meta keys from the generated invoices/package slips for each order line item. I see the code gets all meta data in
    get_order_items
    through

    $data['meta'] = wc_display_item_meta( $item, array(
    	'echo' => false,
    ) );

    It’s possible to filter out specific meta keys with the filter woocommerce_order_item_get_formatted_meta_data (https://stackoverflow.com/a/52684694) – however, I do not want to filter out the meta keys in the admin interface, but only on the generated invoices/package slips.

    Does the plugin offer some kind of conditional tag, similar to something like is_admin, is_product, etc. for checking whether the filter is being called from the plugin?

    Btw it’s an awesome plugin!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter druut

    (@emkemk)

    For now I’m using the code:

    add_filter('woocommerce_order_item_get_formatted_meta_data', function ($formatted_meta, $item) {
        if (is_wc_endpoint_url()) {
            return $formatted_meta;
        }
    
        foreach ($formatted_meta as $key => $meta){
            if(in_array($meta->key, array('delivery_date', 'delivery_text', 'quantity_shipped'))) {
                unset($formatted_meta[$key]);
            }
        }
    
        return $formatted_meta;
    }, 10, 2);

    And this allows me to return the meta data to the API, which is what we need, and it is being filtered from invoices/packing slips, which is also we were looking for. However now I’m not able to see those fields in the admin interface, which is what we prefer.

    • This reply was modified 3 years, 5 months ago by druut.
    • This reply was modified 3 years, 5 months ago by druut.
    • This reply was modified 3 years, 5 months ago by druut.
    Thread Starter druut

    (@emkemk)

    Update: Figured it out!

    By adding an underscore as prefix to the meta data keys, they’re set as private!

    Instead of quantity_shipped it should be _quantity_shipped

    https://wordpress.stackexchange.com/a/183860

    Sorry for spamming this thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filtering out specific meta keys for order line items?’ is closed to new replies.