admin管理员组

文章数量:1122846

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 3 months ago.

Improve this question

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.

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 3 months ago.

Improve this question

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.

Share Improve this question asked May 12, 2024 at 6:12 negar filenegar file 1 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, 2024 at 17:35
  • You have to ask DOKAN's support/dev team how to do this. – Tony Djukic Commented May 13, 2024 at 17:58
Add a comment  | 

1 Answer 1

Reset to default 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' );

本文标签: phpHow do I make a shortcode to display Dokan seller badge list