If you want to get Product id from order id in Woocommerce then fetch order details.

$order = new WC_Order( $order_id );
$items = $order->get_items();

then if you loop through them, you can get all the relevant data:

foreach ( $items as $item ) {
    $product_name = $item['name'];
    $product_id = $item['product_id'];
    $product_variation_id = $item['variation_id'];
}

Have any doubt, then comment here!

2 Comments on Get Product id from order id in Woocommerce

  1. Notice: Undefined variable: order_id in E:\xampp\htdocs\demos\wp-content\plugins\wpjit-restrict\include\enqueue.php on line 81

Leave a Reply

Your email address will not be published. Required fields are marked *