以下应在单个产品页面上显示供应商名称和总销售额:
// 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 文件中。现在应该可以了。
对于自定义产品选项卡,请参阅在 Woocommerce 中编辑产品数据选项卡(官方文档和代码)