phpwordpresswoocommercehook-woocommercedokan

How to add custom badge to store-listing after vender name


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');

Solution

  • 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');