在Woocommerce单个产品页面上显示dokan供应商名称



使用woocommerce,我正在使用Dokan插件,我正在尝试在单个产品页面上显示供应商名称,评级和供应商位置。

我尝试使用此代码来显示供应商名称,但没有运气:

//show store name
add_action( 'woocommerce_single_product_summary', 'show_store_name', 20 );
function show_store_name() {
printf( '<b>Seller Name:</b> <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $store_info['store_name'] );
}

任何帮助,不胜感激。

我不使用 dokan 插件。以下是获取(帖子(作者 ID 并使代码正常工作的方法:

add_action( 'woocommerce_single_product_summary', 'display_author_name', 20 );
function display_author_name() {
// Get the author ID (the vendor ID)
$vendor_id = get_post_field( 'post_author', get_the_id() );
// Get the WP_User object (the vendor) from author ID
$vendor = new WP_User($vendor_id);
$store_info  = dokan_get_store_info( $vendor_id ); // Get the store data
$store_name  = $store_info['store_name'];          // Get the store name
$store_url   = dokan_get_store_url( $vendor_id );  // Get the store URL
$vendor_name = $vendor->display_name;              // Get the vendor name
$address     = $vendor->billing_address_1;           // Get the vendor address
$postcode    = $vendor->billing_postcode;          // Get the vendor postcode
$city        = $vendor->billing_city;              // Get the vendor city
$state       = $vendor->billing_state;             // Get the vendor state
$country     = $vendor->billing_country;           // Get the vendor country
// Display the seller name linked to the store
printf( '<b>Seller Name:</b> <a href="%s">%s</a>', $store_url, $store_name );
}

代码进入函数.php活动子主题(或活动主题(的文件。这现在应该有效。

但我不知道如何获得供应商评级和位置。你最好问问道坎的支持。

代码基于此相关线程。

这应该可以做到:

$vendor_id = dokan_get_seller_id_by_order( $order->ID );
$vendor_data = get_user_meta( $vendor_id );
echo $vendor_data["first_name"][0]." ".$vendor_data["last_name"][0];

最新更新