Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rodriguezavellan/b74537530ecd54151f01daaae610f48f to your computer and use it in GitHub Desktop.

Select an option

Save rodriguezavellan/b74537530ecd54151f01daaae610f48f to your computer and use it in GitHub Desktop.

Revisions

  1. rodriguezavellan created this gist May 6, 2020.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    /**
    * Add a custom product data tab
    */
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {

    // Adds the new tab

    $tabs['test_tab'] = array(
    'title' => __( 'Vendor Bio', 'woocommerce' ),
    'priority' => 50,
    'callback' => 'woo_new_product_tab_content'
    );

    return $tabs;

    }
    function woo_new_product_tab_content() {

    // The new tab content

    global $product;
    $seller = get_post_field( 'post_author', $product->get_id());
    $author = get_user_by( 'id', $seller );
    $vendor = dokan()->vendor->get( $seller );

    $store_info = dokan_get_store_info( $author->ID );

    if ( !empty( $store_info['store_name'] ) ) { ?>
    <span class="details">
    <?php printf( 'Sold by: <a href="%s">%s</a>', $vendor->get_shop_url(), $vendor->get_shop_name() ); ?>
    </span>
    <br/>
    <?php
    }

    global $product;
    $seller = get_post_field( 'post_author', $product->get_id());
    $author = get_user_by( 'id', $seller );
    $vendor = dokan()->vendor->get( $seller );

    $store_info = dokan_get_store_info( $author->ID );

    if ( !empty( $store_info['vendor_biography'] ) ) { ?>
    <span class="details">
    <?php printf( $vendor->get_vendor_biography() ); ?>
    </span>
    <?php
    }
    }