thundernet8 / Tint-Pro

WordPress高级扩展主题Tinection Two/Tint
https://webapproach.net
GNU General Public License v3.0
44 stars 12 forks source link

[建议]希望能显示购买了商品的用户邮箱 #10

Closed fantastlcok closed 7 years ago

fantastlcok commented 7 years ago

方便在商品更新时通知购买了商品的用户。

另外推荐 邮件队列 插件 SMTP Mailing Queue,支持 SMTP。

不过好像这款插件和主题不兼容,主题不能使用第三方SMTP插件吗?

thundernet8 commented 7 years ago

已添加至商品编辑页面供管理员查看

fantastlcok commented 7 years ago

@thundernet8 能直接给现成的代码么,急用。

thundernet8 commented 7 years ago

@fantastlcok

/**
 * 查找某个商品的购买用户的邮箱
 *
 * @param $product_id
 * @return array|null|object
 */
function tt_get_buyer_emails($product_id) {
    $cache_key = 'tt_product' . $product_id . '_buyer_emails';
    if($cache = get_transient($cache_key)) {
        return maybe_unserialize($cache);
    }

    global $wpdb;
    $prefix = $wpdb->prefix;
    $orders_table = $prefix . 'tt_orders';
    $sql = sprintf("SELECT `user_id` FROM $orders_table WHERE `deleted`=0 AND `order_status`=%d AND `product_id`=%d ORDER BY `id` DESC", OrderStatus::TRADE_SUCCESS, $product_id); 
    $results = $wpdb->get_col($sql);

    if(!$results || count($results) < 1) return null;

    $user_emails = $wpdb->get_col(sprintf("SELECT `user_email` FROM $wpdb->users WHERE ID IN (%s) AND wp_users.user_email<>''", implode(',', $results)));

    set_transient($cache_key, maybe_serialize($user_emails), 3600*24);
    return $user_emails;
}
thundernet8 commented 7 years ago
function tin_get_buyer_emails($product_id) {
    $cache_key = 'tt_product' . $product_id . '_buyer_emails';
    if($cache = get_transient($cache_key)) {
        return maybe_unserialize($cache);
    }

    global $wpdb;
    $prefix = $wpdb->prefix;
    $orders_table = $prefix . 'tt_orders';
    $sql = sprintf("SELECT `user_id` FROM $orders_table WHERE `deleted`=0 AND `order_status`=%d AND `product_id`=%d ORDER BY `id` DESC", OrderStatus::TRADE_SUCCESS, $product_id);
    $results = $wpdb->get_col($sql);

    if(!$results || count($results) < 1) return null;

    $user_emails = $wpdb->get_col(sprintf("SELECT `user_email` FROM $wpdb->users WHERE ID IN (%s) AND $wpdb->users.user_email<>''", implode(',', $results)));

    set_transient($cache_key, maybe_serialize($user_emails), 3600*24);
    return $user_emails;
}

先将这个函数加到functions.php