在 Woocommerce 单个产品页面上显示 dokan 供应商名称 [英] Display dokan vendor name on Woocommerce single product pages

查看:41
本文介绍了在 Woocommerce 单个产品页面上显示 dokan 供应商名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With woocommerce I am using Dokan plugin and I am trying to display the vendor name, rating and vendor location on single product pages.

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

I tried this code to display vendor name but no luck:

//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 并使您的代码正常工作的方法:

I don't use dokan plugin. Here is the way to get the (post) author ID and to make your code work:

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 文件中.现在应该可以了.

Code goes in function.php file of your active child theme (or active theme). This should work now.

但我不知道如何获得供应商评级和位置.您最好咨询 Dokan 支持人员.

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

代码基于这个相关主题.

这篇关于在 Woocommerce 单个产品页面上显示 dokan 供应商名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆