Automatic add product when create order
-
Hi,
I would like to ask how I can change this part of the code so that it automatically adds the product to the end of the order after the order is created. Now this product is added to the beginning of my order.
Thank you very much
function add_item_to_existing_order($order_id) { $product_id = 14356; $quantity = 1; $order = wc_get_order($order_id); if (!$order) { //echo '<script>alert("No order")</script>'; return; } $product = wc_get_product($product_id); if (!$product) { //echo '<script>alert("No product")</script>'; return; } // Add the product to the order $order->add_product($product, $quantity); // Save the changes // $order->calculate_totals(); $order->save(); } add_action('woocommerce_new_order', 'add_item_to_existing_order');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Automatic add product when create order’ is closed to new replies.