WooFrance Dépannage et support WordPress WooCommerce Forums Forum de Support WooCommerce Commande WooCommerce en php n’envoit pas de mail de confirmation

Étiqueté : 

Affichage de 1 message (sur 1 au total)
  • Auteur
    Messages
  • #517817
    Vivian
    Participant
    Points: 16 pts

    Bonjour à tous !
    Je crée un plugin woordpress qui génère un code, le lie à un produit virtuel téléchargeable. J’utilise ce code, une fois validé pour créer une commande woocommerce en php. Lorsque je set la commande à ‘completed’, l’email n’est jamais envoyé au client automatiquement. Je suis obligé de cahnger de status dans le tableau de bord pour remettre expédié et la le mail part.

    J’ai essayé de faire le changement de statut avec : $order->set_status(‘completed’) $order->update_status(‘completed’)

    Ce que je voudrais, c’est que le plugin crée une commande woocommerce avec l’adresse email du client lorsque le code est validé. (le client n’a pas besoin d’avoir un compte pour commander) La commande va directement à l’expédition, et l’email de téléchargement est envoyé. Le client ouvre l’e-mail et télécharge le fichier. Je ne comprends pas quel est le problème, si quelqu’un a déjà rencontré ce problème ou si quelqu’un a une idée, je serais ravi de l’entendre.

    Voici mon code :
    `
    <pre class=”lang-php s-code-block”><code class=”hljs language-php”><span class=”hljs-function”><span class=”hljs-keyword”>function</span> <span class=”hljs-title”>ode_cd_traitment_download_code_form</span>()
    </span>{
    <span class=”hljs-keyword”>if</span> (<span class=”hljs-variable”>$_SERVER</span>[<span class=”hljs-string”>’REQUEST_METHOD'</span>] === <span class=”hljs-string”>’POST'</span> && <span class=”hljs-keyword”>isset</span>(<span class=”hljs-variable”>$_POST</span>[<span class=”hljs-string”>’code'</span>]) && <span class=”hljs-keyword”>isset</span>(<span class=”hljs-variable”>$_POST</span>[<span class=”hljs-string”>’email'</span>])) {
    <span class=”hljs-variable”>$code</span> = <span class=”hljs-title function_ invoke__”>sanitize_text_field</span>(<span class=”hljs-variable”>$_POST</span>[<span class=”hljs-string”>’code'</span>]);
    <span class=”hljs-variable”>$email</span> = <span class=”hljs-title function_ invoke__”>sanitize_text_field</span>(<span class=”hljs-variable”>$_POST</span>[<span class=”hljs-string”>’email'</span>]);
    <span class=”hljs-variable”>$remaining_uses</span> = <span class=”hljs-title function_ invoke__”>remaining_uses</span>(<span class=”hljs-variable”>$code</span>);
    <span class=”hljs-variable”>$validation_result</span> = <span class=”hljs-title function_ invoke__”>ode_cd_validate_data_download_form</span>(<span class=”hljs-variable”>$code</span>, <span class=”hljs-variable”>$email</span>, <span class=”hljs-variable”>$remaining_uses</span>);

    <span class=”hljs-keyword”>if</span> (!<span class=”hljs-keyword”>empty</span>(<span class=”hljs-variable”>$validation_result</span>)) {
    <span class=”hljs-keyword”>return</span> <span class=”hljs-variable”>$validation_result</span>;
    } <span class=”hljs-keyword”>else</span> {
    <span class=”hljs-keyword”>if</span> (<span class=”hljs-title function_ invoke__”>ode_cd_code_exists_in_database</span>(<span class=”hljs-variable”>$code</span>)) {
    <span class=”hljs-title function_ invoke__”>decrement_uses</span>(<span class=”hljs-variable”>$code</span>);
    <span class=”hljs-variable”>$new_remaining_uses</span> = <span class=”hljs-title function_ invoke__”>remaining_uses</span>((<span class=”hljs-variable”>$code</span>));

    <span class=”hljs-title function_ invoke__”>ode_cd_create_order</span>(<span class=”hljs-variable”>$code</span>, <span class=”hljs-variable”>$email</span>);

    <span class=”hljs-title function_ invoke__”>wp_redirect</span>(<span class=”hljs-title function_ invoke__”>home_url</span>(<span class=”hljs-string”>”/test-page/?success=true&remaining_uses=<span class=”hljs-subst”>$new_remaining_uses</span>”</span>));
    <span class=”hljs-keyword”>exit</span>;
    } <span class=”hljs-keyword”>else</span> {
    <span class=”hljs-keyword”>return</span> <span class=”hljs-string”>”Le code renseigner est inconnue de notre service.”</span>;
    }
    }
    }
    }
    <span class=”hljs-title function_ invoke__”>add_action</span>(<span class=”hljs-string”>’init'</span>, <span class=”hljs-string”>’ode_cd_traitment_download_code_form'</span>);

    <span class=”hljs-function”><span class=”hljs-keyword”>function</span> <span class=”hljs-title”>ode_cd_create_order</span>(<span class=”hljs-params”><span class=”hljs-variable”>$code</span>, <span class=”hljs-variable”>$email</span></span>)
    </span>{

    <span class=”hljs-variable”>$product_id</span> = <span class=”hljs-title function_ invoke__”>get_product_id_by_unique_code</span>(<span class=”hljs-variable”>$code</span>);

    <span class=”hljs-variable”>$order</span> = <span class=”hljs-title function_ invoke__”>wc_create_order</span>();
    <span class=”hljs-variable”>$product</span> = <span class=”hljs-title function_ invoke__”>wc_get_product</span>(<span class=”hljs-variable”>$product_id</span>);
    <span class=”hljs-variable”>$order</span>-><span class=”hljs-title function_ invoke__”>add_product</span>(<span class=”hljs-variable”>$product</span>, <span class=”hljs-number”>1</span>);
    <span class=”hljs-variable”>$order</span>-><span class=”hljs-title function_ invoke__”>set_billing_email</span>(<span class=”hljs-variable”>$email</span>);
    <span class=”hljs-comment”>//$order->set_status(‘completed’);</span>
    <span class=”hljs-variable”>$order</span>-><span class=”hljs-title function_ invoke__”>save</span>();
    <span class=”hljs-comment”>$order->update_status(‘completed’);</span>
    <span class=”hljs-comment”>$order->save();</span>
    }</code><code></code>`
    Bonne journée et merci d’avance à ceux qui répondront.

    depanagewp
Affichage de 1 message (sur 1 au total)
  • Vous devez être connecté pour répondre à ce sujet.