在Woocommerce单品页面上显示Dokan供应商名称和总销售额

问题描述 投票:2回答:1

使用Woocommerce和Dokan插件。我试图在单个产品页面上的供应商信息选项卡上显示供应商名称和总销售额(以确保客户信心)。

基于“Display dokan vendor name on Woocommerce single product pages”问题线程,我尝试使用此代码显示供应商名称和总销售额:

//show vendor total sales
add_action( 'woocommerce_single_product_summary', 'show_total_sales', 20 );
function show_total_sales() {    
    printf( '<b>Seller Name:</b> <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $store_info['total_sales'] );
}

但它不起作用。我怎样才能使它工作?

php wordpress woocommerce vendor dokan
1个回答
0
投票

以下内容应显示单个产品页面上的供应商名称和总销售额:

// Display vendor total sales
add_action( 'woocommerce_single_product_summary', 'show_total_sales', 20 );
function show_total_sales() {
    global $product;

    $vendor_id   = get_post_field( 'post_author', $product->get_id() ); // Get the author ID (the vendor ID)
    $vendor      = new WP_User($vendor_id); // Get the WP_User object (the vendor) from author ID

    $store_url   = dokan_get_store_url( $vendor_id );  // Get the store URL
    $store_info  = dokan_get_store_info( $vendor_id ); // Get the store data
    $store_name  = $store_info['store_name'];          // Get the store name

    // Output display
    printf( '<p><strong>%s:</strong> <a href="%s">%s (%s %s)</a></p>', 
        __("Seller Name", "woocommerce"), 
        dokan_get_store_url( $vendor_id ),
        $vendor->display_name,
        $store_info['total_sales'],
        _n( "sale", "sales", $store_info['total_sales'], "woocommerce" )
    );
}

代码位于活动子主题(或活动主题)的function.php文件中。这应该现在有效。


有关自定义产品标签,请参阅Editing product data tabs in Woocommerce (official docs and code)

© www.soinside.com 2019 - 2024. All rights reserved.