<?php
if (!defined('ABSPATH')) {
    exit;
}
function drop_print_snapshot_sku_onto_order_line($item, $cart_item_key, $values, $order) {
    if (empty($values['variation_id'])) {
        return;
    }
    $sku = get_post_meta(absint($values['variation_id']), '_drop_print_sku', true);
    if (empty($sku)) {
        return;
    }
    $item->add_meta_data('_dp_sku', $sku, true);
}
add_action('woocommerce_checkout_create_order_line_item', 'drop_print_snapshot_sku_onto_order_line', 10, 4);
function drop_print_snapshot_sizing_onto_order_line($item, $cart_item_key, $values, $order) {
    if (empty($values['variation_id'])) {
        return;
    }
    $sizing = get_post_meta(absint($values['variation_id']), '_drop_print_sizing', true);
    if (empty($sizing)) {
        return;
    }
    $item->add_meta_data('_dp_sizing', is_array($sizing) ? wp_json_encode($sizing) : $sizing, true);
}
add_action('woocommerce_checkout_create_order_line_item', 'drop_print_snapshot_sizing_onto_order_line', 10, 4);
