

add_action('wp_ajax_place_order', 'place_custom_order'); add_action('wp_ajax_nopriv_place_order', 'place_custom_order'); function place_custom_order() { $phone = sanitize_text_field($_POST['phone']); $variation_id = intval($_POST['variation_id']); $product = wc_get_product($variation_id); $order = wc_create_order(); $order->add_product($product, 1); $order->set_address(['phone' => $phone], 'billing'); $order->calculate_totals(); $order->update_status('processing'); wp_die('success'); }