Filter out unwanted order item meta data from Woocommerce email notifications

前端 未结 4 1838
悲哀的现实
悲哀的现实 2021-01-20 17:20

In the order email templates (for example email-order-items.php), WooCommerce uses the function wc_display_item_meta to display product details in

4条回答
  •  感情败类
    2021-01-20 18:12

    Try the following without any guarantee (as I don't really have the real necessary keys):

    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('Qty Selector', 'Qty', 'Total') ) )
                unset($formatted_meta[$key]);
        }
        return $formatted_meta;
    }
    

    Code goes in function.php file of your active child theme (active theme). Tested with other meta data than yours and works. I hope it will work for you too.

    Now, the hook used with this code is the right filter hook. It's located in the WC_Order_Item method get_formatted_meta_data() and allows to filter the order item meta data.

提交回复
热议问题