Restricted Order on creating programmatically
-
Hi,
When I am creating an order in WC manually the orders are displayed in “Store Vendors” page, but when I create order programmatically they are not shown:
$order = wc_create_order(); $customer_data = array( 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@example.com', 'phone' => '123456789', 'address_1' => '123 Main St', 'city' => 'Anytown', 'postcode' => '12345', 'country' => 'US', ); // Set customer information for the order $order->set_address($customer_data, 'billing'); $order->set_address($customer_data, 'shipping'); $product = wc_get_product($product_id); if ($product) { $item = $order->add_product($product, 1); // Quantity: 1 if ($order->get_status() === 'pending') { $order->update_status('processing'); } else { // echo 'Order status is not Pending payment.'; } if ($item) { // Calculate totals $order->calculate_totals(); // Update product meta // Save the order $order->save(); // Get the order ID $order_id = $order->get_id(); if ($order_id) { echo 'Order created successfully. Order ID: ' . $order_id; } else { echo 'Error saving the order.'; } } else { echo 'Error adding product to the order.'; } } else { echo 'Product not found.'; } } The notification for order is displayed in this case but when I click on the order id: Restricted Order: You don't have permission to access this page. Please contact your Store Admin for assistance. This is shown, Where i am missingm is there an event need to be triggerred after order creation.
The topic ‘Restricted Order on creating programmatically’ is closed to new replies.