WooFrance Dépannage et support WordPress WooCommerce › Forums › Forum de Support WooCommerce › Woocommerce programmed order does not trigger confirmation email
- Ce sujet contient 0 réponse, 1 participant et a été mis à jour pour la dernière fois par Vivian, le il y a 9 mois et 2 semaines.
-
AuteurMessages
-
8 février 2024 à 10 h 55 min #517476
Hi everybody !
I create a woordpress plugin that generates a code, links it to a downloadable virtual product. I use this code, once validated to create a woocommerce order in php. When I change the order status the email is never sent to the customer. However, on the production site, customers receive confirmation emails correctly. (The plugin is not on the production site).I tried to do the status change with :
$order->set_status('completed')
$order->update_status('completed')
I’ve tried to do it manually in the commands dashboard, but it doesn’t change anything.What I’d like is for the plugin to create a woocommerce order with the customer’s email address when the code is validated. (the customer doesn’t have to have an account to order) The order goes directly to Shipping, and the download email is sent. The customer opens the e-mail and downloads the file. I don’t understand what the problem is, if someone has already come across this problem or if someone has an idea I’d love to hear from you.
I’ll share my code with you:
function ode_cd_traitment_download_code_form() { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['code']) && isset($_POST['email'])) { $code = sanitize_text_field($_POST['code']); $email = sanitize_text_field($_POST['email']); $remaining_uses = remaining_uses($code); $validation_result = ode_cd_validate_data_download_form($code, $email, $remaining_uses); if (!empty($validation_result)) { return $validation_result; } else { if (ode_cd_code_exists_in_database($code)) { decrement_uses($code); $new_remaining_uses = remaining_uses(($code)); ode_cd_create_order($code, $email); wp_redirect(home_url("/test-page/?success=true&remaining_uses=$new_remaining_uses")); exit; } else { return "Le code renseigner est inconnue de notre service."; } } } } add_action('init', 'ode_cd_traitment_download_code_form'); function ode_cd_create_order($code, $email) { $product_id = get_product_id_by_unique_code($code); $order = wc_create_order(); $product = wc_get_product($product_id); $order->add_product($product, 1); $order->set_billing_email($email); //$order->set_status('completed'); $order->save(); // $order->update_status('completed'); //$order->save(); }
Have a nice day and thanks in advance to those who reply.
- Ce sujet a été modifié le il y a 9 mois et 2 semaines par Vivian.
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.