【问题标题】:WooCommerce - Send monthly emails based on order dateWooCommerce - 根据订单日期发送每月电子邮件
【发布时间】:2019-08-25 16:22:42
【问题描述】:

嘿哟,

所以我目前正在维护/进一步开发一个基于 Wordpress 的网站,该网站使用 WooCommerce 来处理订单。该系统由购买每月订阅的客户在各种事务上获得帮助,并且在订阅结束时,我们希望通过电子邮件通知用户订阅已结束(这是当前手头的问题)。

我查看了MailChimp for WooCommerce-plugin(s),但很快意识到这很难确保客户在购买后一个月收到电子邮件,而不仅仅是在每个开始时月。此外,我查看了WooCommerce-query documentation,这使得创建自定义函数、获取每个完成的订单、检查当前日期是否是购买后一个月以及运行 PHP 的mail() 成为可能功能。但我并没有考虑太多,只是将其保留为“一个想法”。

因此,我在这里。如果有人有任何建议或想法,将不胜感激!

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    一个月前已经这样做了...
    1.注册一个wordpress cron see in the codex
    2. 在 cron 回调中获取来自某个日期或时间跨度的所有订单,如下所示:

    $args = array(
        'status' => 'completed',
        'date_paid' => '<' . ( time() - 561600) // for a timespan
        // 'date_paid' => (time() - 561600) for a fixed date
    );
    $orders = wc_get_orders( $args );
    

    check the documentation here

    1. 遍历订单
    2. 从订单中获取客户电子邮件地址

      $order = $order->get_data();
      $mail = $order['billing']['email'];

    3. 发送您的邮件。 wp_mail() is your friend

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2017-08-08
      相关资源
      最近更新 更多