0

I am going to add the Dokan seller badge list to the single product page by creating a shortcode so that the tooltip is also displayed. Thank you for your guidance.

2
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented May 13 at 17:35
  • You have to ask DOKAN's support/dev team how to do this. Commented May 13 at 17:58

1 Answer 1

1
// Add shortcode to display Dokan Seller Badge on Single Product Page
function display_dokan_seller_badge() {
    if ( function_exists( 'dokan_get_vendor_by_product' ) ) {
        global $post;
        $product_id = $post->ID; // Get the current product ID
        $vendor = dokan_get_vendor_by_product( $product_id ); // Get the vendor information from the product ID

        if ( $vendor ) {
            $vendor_id = $vendor->get_id(); // Get the vendor ID

            // Fetch the seller badge meta associated with the vendor ID
            $badge_id = get_user_meta( $vendor_id, 'dokan_seller_badge_id', true );

            if ( !empty( $badge_id ) ) {
                $badge_image = wp_get_attachment_image( $badge_id, 'full' ); // Get the seller badge image

                if ( !empty( $badge_image ) ) {
                    return '<div class="dokan-seller-badge">' . $badge_image . '</div>'; // Return the badge image wrapped in a div
                }
            } else {
                return '<p>No Seller Badge Available</p>'; // If no badge is found
            }
        }
    }

    return ''; // Return empty if no vendor or badge is found
}

// Register the shortcode [dokan_seller_badge]
add_shortcode( 'dokan_seller_badge', 'display_dokan_seller_badge' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.