首页 文章

在WooCommerce中向订单上的客户发送电子邮件

提问于
浏览
3

我的Wordpress安装有问题,或WooCommerce更具体 .

我在过去几个月一直工作的客户希望每次客户完成/支付订单时,除了标准订单确认电子邮件之外,还会将自定义电子邮件发送到他的电子邮件地址 .

简而言之: I need to send a custom email to the customer when the order is completed. How can I do that inside the functions.php?

我尝试使用官方文档中描述的各种钩子和函数,但无法弄清楚 .

Wordpress版本为3.8.1,WooCommerce版本为2.0.20 .

先感谢您 .

3 回答

  • 3

    您可以使用名为woocommerce_payment_complete的操作执行此操作;

    $order = new WC_Order( $order_id );
    
    function order_completed( $order_id ) {
        $order = new WC_Order( $order_id );
        $to_email = $order["billing_address"];
        $headers = 'From: Your Name <your@email.com>' . "\r\n";
        wp_mail($to_email, 'subject', 'message', $headers );
    
    }
    
    add_action( 'woocommerce_payment_complete', 'order_completed' );
    
  • 4

    我解决了这个问题 . 我一直在使用错误的钩子 . 这是问题的主要原因 . 正确的钩子名称是“ woocommerce_thankyou ” . 我改变了使用这个钩子的功能后,一切都很顺利 .

  • 0

    由于三个主要原因,我认为您没有检索邮件

    • SMTP插件需要配置为correclty,如果它是anabled

    • 尝试PHP邮件功能 mail('caffeinated@example.com', 'My Subject', $message);

    • 添加要添加的操作的优先级为 add_action( 'woocommerce_payment_complete', 'order_completed',1 );

相关问题