How to add the custom badge to store-listing after the vendor name with a specific vendor id? the below code works but show for all vendors, indeed I need to run this code only for a particular vendor. enter image description here

     function display_author_name_store_listing() {
     if (!is_plugin_active('dokan-lite/dokan.php')){
         return"";
     }
     printf("custom badge");
     }   
     add_action( 'dokan_store_list_loop_after_store_name', 'display_author_name_store_listing');

推荐答案

function display_author_name_store_listing() {
    if (!is_plugin_active('dokan-lite/dokan.php')) {
        return "";
    }

    global $wpdb;

    $ubicon = $wpdb->prefix . 'ubicon'; //user badge verified users
    // Get the author ID (the vendor ID)
    $vendor_id = get_post_field('post_author', get_the_id());

    $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM $ubicon WHERE link_id = %d", $vendor_id));

    $bage_url = $result->badge_url;
    return $bage_url;
}

add_action('dokan_store_list_loop_after_store_name', 'display_author_name_store_listing');

Php相关问答推荐

如何在Laravel Controller中存储文本区域值?

将一个数字分配到一系列因素中(就像贪婪算法)

在WooCommerce Checkout帐单地址字段后插入自定义按钮

Mysqli_stmt::Execute():结果字段元数据中存在过早的EOF

WooCommerce管理订单列表自定义列不显示值

为什么正则表达式与得到的文本块之前得到的也行?

将文件添加到存档,而不重建存档

使用MySQLi使用连接字符串设置字符集

如果为布尔值,则 for each 循环重新启动

Laravel服务Provider 没有向服务类注入价值

如果WooCommerce购物车在 checkout 时被清空,请重定向至store 页面

隐藏WooCommerce管理子菜单;主页;来自store 经理

在WooCommerce循环中添加子类别和产品之间的分隔符

PHP 中的 libgd 无法读取 Apache 配置中的 SetEnv GDFONTPATH

正则表达式将文本替换为标签 html 以字符开头

我的功能以舒适的方式显示数组 struct

我需要一个正则表达式模式来获取在不包含特定字符串后面的模式中的文本

PHP 中的正则表达式,具有字符范围,但不包括特定字符

如何在 Process facade 中转义特殊字符?

getenv() 有时在 CodeIgniter 4 中返回 false.为什么?