which hook use for new orders?
-
add_action('woocommerce_checkout_order_processed','order_to_tsm',10, 3); function order_to_tsm($order_id, $posted_data, $order){ $order = wc_get_order( $order_id ); $first_name = $order->get_billing_first_name(); $last_name = $order->get_billing_last_name(); $phone = $order->get_billing_phone(); $email = $order->get_billing_email(); $city = $order->get_billing_city(); $address = $order->get_billing_address_1(); $price = $order->get_total(); $items = $order->get_items(); $payment_date = $order->get_date_paid(); $temp2 = date_create($payment_date); $datePayment = date_format($temp2, "Y/m/d H:i:s"); $order_date = $order->get_date_created();; $temp = date_create($order_date); $date = date_format($temp, "Y/m/d H:i:s"); $products = []; foreach ($items as $item) { $product_name = $item->get_name(); $product_quantity = $item->get_quantity(); $products[] = $product_name . ' x ' . $product_quantity; } $json = implode(", ", $products); $message = 'U?sakymo data: ' . $date . "\n" . 'Vardas: ' . $first_name . "\n" . 'Pavard?: ' . $last_name . "\n" . 'Miestas: ' . $city . "\n" . 'Adresas: ' . $address . "\n" . 'Prek?s: ' . $json ."\n" . 'Kaina: ' . $price . "\n" . 'Apmokejimo data: ' . $datePayment; $TotalOrders = [ 'email' => $email, 'phone' => $phone, 'objectname' => 'web_testas', 'msg' => $message ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'url', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $TotalOrders, CURLOPT_HTTPHEADER => array( 'HTTP_X_REQUESTED_WITH: XMLHttpRequest' ), )); curl_exec($curl); curl_close($curl); }
Hi , which hook should i use to trigger function on new order (after order is paid)?
woocommerce_payment_complete – wont trigger
woocommerce_payment_complete_order_status – wont trigger and bug(makes paid orders status canceled)
woocommerce_checkout_order_processed – works, but trigger before payment
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘which hook use for new orders?’ is closed to new replies.