gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:24:40 25 4
gpt4 key购买 nike

使用 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 );
}

代码位于事件子主题(或事件主题)的 function.php 文件中。这现在应该可以工作了。

But I don't know how to get vendor rating and location. You should better ask Dokan support.



代码基于 this related thread .

关于php - 在 Woocommerce 单个产品页面上显示 dokan 供应商名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51145071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com