Should I create shortcode first? Or I just directly use the meta key from my 3rd party plugin?
I will show you the code: Below is where my tracking number stored:
function save_meta_box($post_id, $post)
{
if (isset($_POST['dianxiaomi_tracking_number'])) {
// Download data
$tracking_provider = woocommerce_clean($_POST['dianxiaomi_tracking_provider']);
update_post_meta($post_id, '_dianxiaomi_tracking_provider', $tracking_provider);
foreach ($this->dianxiaomi_fields as $field) {
if ($field['type'] == 'date') {
update_post_meta($post_id, '_' . $field['id'], woocommerce_clean(strtotime($_POST[$field['id']])));
} else {
update_post_meta($post_id, '_' . $field['id'], woocommerce_clean($_POST[$field['id']]));
}
}
}
}
And my question is, should I create a shortcode first based on the meta key(_danxiaomi_tracking_number) like below?
add_filter( 'woocommerce_email_order_meta_fields', 'add_tracking_number_to_order_meta_fields', 10, 3 );
function add_tracking_number_to_order_meta_fields( $fields, $sent_to_admin, $order ) {
$tracking_number = get_post_meta( $order->get_id(), '_dianxiaomi_tracking_number', true ); // replace '_dianxiaomi_tracking_number' with the actual meta key used to store the tracking number
if ( $tracking_number ) {
$fields['{dianxiaomi_tracking_number}'] = array(
'label' => 'Tracking Number',
'value' => $tracking_number,
);
}
return $fields;
I’ve tried both [wec_order_meta key=”_dianxiaomi_tracking_number”] and [wec_order_meta key=”dianxiaomi_tracking_number”], nothing happened. There is no output in my email.
Or should I copy this meta key to order meta? not post meta?