I am stuck on one problem, for my E-commerce website after placing order on i want to show random number for each product in order details section. I have tried this : in theme(function.php)

add_action( 'woocommerce_order_status_processing', 'add_unique_id');


function add_unique_id($order_id) {
$order = new WC_Order( $order_id );
$items = $order->get_items(); 
  foreach ($items as $item_id => $product )
    $gen_id ="Hi Dad!";
  wc_add_order_item_meta($item_id, 'unique_id', $gen_id);

But by using this i am not getting unique number for each product.

I want to add random number in below red portion in image of Thank You page.

enter image description here

please help to resolve. thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.