如何在 Wordpress 仪表板小部件中显示 WooCommerce 新用户注册

编程入门 行业动态 更新时间:2024-10-19 06:26:26
本文介绍了如何在 Wordpress 仪表板小部件中显示 WooCommerce 新用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想创建一个 wordpress 仪表板小部件,在仪表板上显示 WooCommerce 注册用户.

目前正在使用他的代码

add_action('wp_dashboard_setup', 'register_my_dashboard_widget');函数 register_my_dashboard_widget() {wp_add_dashboard_widget('my_dashboard_widget','我的仪表板小部件','my_dashboard_widget_display');}函数 my_dashboard_widget_display() {echo '这里的上下文';}

我创建了一个小部件,但不知道如何在那里显示注册用户.

解决方案

注释并在代码中添加说明.

使用的函数:

get_users() - 检索列表用户匹配标准.$argswp_dashboard_setup() - 注册仪表板小部件.

function action_wp_dashboard_setup() {wp_add_dashboard_widget('my_dashboard_widget',//Widget slug.esc_html__( 'My Dashboard Widget', 'woocommerce' ),//标题'my_dashboard_widget_function'//显示函数);}add_action('wp_dashboard_setup', 'action_wp_dashboard_setup');函数 my_dashboard_widget_function() {//参数$args = 数组('role_in' =>array( 'administrator', 'customer'),//用户角色'orderby' =>'用户注册','订单' =>'ASC','数字' =>-1//全部);//获取用户$users = get_users( $args );//输出echo '

';echo '';//真的如果 ( $users ) {foreach ( $users 作为 $user ) {echo ' 用户名 = ' .$user->display_name .'</li>';}} 别的 {echo '没有找到用户';}回声'</ul>';回声'</div>';}

I would like to create a wordpress dashboard widget which shows WooCommerce registered user at dashboard.

Currently using his code

add_action( 'wp_dashboard_setup', 'register_my_dashboard_widget' );
function register_my_dashboard_widget() {
    wp_add_dashboard_widget(
        'my_dashboard_widget',
        'My Dashboard Widget',
        'my_dashboard_widget_display'
    );

}

function my_dashboard_widget_display() {
    echo 'the context here';
}

I have created a widget but don't know how to show registered user there.

解决方案

Comment with explanation added in the code.

Functions used:

get_users() - Retrieve list of users matching criteria. $args wp_dashboard_setup() - Registers dashboard widgets.

function action_wp_dashboard_setup() {
    wp_add_dashboard_widget( 
        'my_dashboard_widget', // Widget slug. 
        esc_html__( 'My Dashboard Widget', 'woocommerce' ), // Title
        'my_dashboard_widget_function' // Display function
    );
}
add_action( 'wp_dashboard_setup', 'action_wp_dashboard_setup' );

function my_dashboard_widget_function() {
    // Args
    $args = array(
        'role_in'  => array( 'administrator', 'customer'), // user roles
        'orderby'  => 'user_registered',
        'order'    => 'ASC',
        'number'   => -1 // all
    );

    // Get users
    $users = get_users( $args );

    // Output
    echo '<div class="main">';
    echo '<ul>';

    // True
    if ( $users ) {
        foreach ( $users as $user ) {
            echo '<li>User name = ' .  $user->display_name . '</li>';
        }
    } else {
        echo '<li>no users found</li>';
    }

    echo '</ul>';
    echo '</div>';
}

这篇关于如何在 Wordpress 仪表板小部件中显示 WooCommerce 新用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 02:58:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仪表板   新用户注册   部件   如何在   Wordpress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!