Git Product home page Git Product logo

Comments (4)

thundernet8 avatar thundernet8 commented on June 14, 2024

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

from tint-pro.

fantastlcok avatar fantastlcok commented on June 14, 2024

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

from tint-pro.

thundernet8 avatar thundernet8 commented on June 14, 2024

@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;
}

from tint-pro.

thundernet8 avatar thundernet8 commented on June 14, 2024
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

from tint-pro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.