Recently, I asked, and received the answers for two solutions:
of some order items. Solutions that will work only for WooCommerce email notifications sent on completed orders.
The problem with the received solutions is that in both, to limit them only to email notifications, the is_wc_endpoint_url()
function is used, which, in my particular case (I don't know why!), makes them to work only for notifications sent to administrators, but not to customers, who are in fact the main recipients of the metadata in question.
Is there any way to around this issue with the is_wc_endpoint_url()
function?
The first answer, adding metadata:
function action_woocommerce_order_item_meta_start( $item_id, $item, $order, $plain_text ) {
// On email notifications
if ( ! is_wc_endpoint_url() && $item->is_type('line_item') ) {
echo '<ul class="wc-item-meta"><li><strong class="wc-item-meta-label">Label</strong><p>Value order id = ' . $order->get_id() . '</p></li></ul>';
}
}
add_action( 'woocommerce_order_item_meta_start', 'action_woocommerce_order_item_meta_start', 10, 4 );
The second answer (one of the options), changing metadata:
function filter_woocommerce_order_item_get_formatted_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 ) {
$formatted_meta[$key]->display_key = 'new key';
$formatted_meta[$key]->display_value = 'new value';
}
return $formatted_meta;
}
add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'filter_woocommerce_order_item_get_formatted_meta_data', 10, 2 );