Woocommerce 在管理订单详细信息页面中显示供应商详细信息,例如供应商名称、商店名称、联系方式和供应商地址 (Dokan)
Woocommerce Show vendor Details such as Vendor Name, Store Name, Contact Details and Vendor Address (Dokan) in admin order details page
我们想在订单管理订单详细信息页面中显示商店名称、供应商名称和供应商联系方式。
我正在使用 答案代码来显示发票中每个产品的商店名称。
现在我们要显示供应商名称和供应商联系方式的详细信息。
Order Page Screenshot
我的尝试:
// Adding Vendor Details admin shop_order pages
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
// Empty array
$shop_names = array();
// Output
echo '<h4>' . __( 'Store Name: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();
// NOT in array
if ( ! in_array( $shop_name, $shop_names ) ) {
// Push to array
$shop_names[] = $shop_name;
// Output
echo '<p>' . $shop_name . '</p>';
}
}
// Empty array
$store_phones = array();
// Output
echo '<h4>' . __( 'Seller Contact: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$store_phone = $vendor->get_phone();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $store_phone = dokan()->vendor->get( $author_id )->get_store_phone();
// NOT in array
if ( ! in_array( $store_phone, $store_phones ) ) {
// Push to array
$store_phone[] = $store_phone;
// Output
echo '<p>' . $store_phone . '</p>';
}
}
}
通过使用此代码,我们获得了商店名称,但我们无法获得供应商名称和供应商联系方式。
您在此代码中的问题 $store_phone[] = $store_phone;
替换为 $store_phones[] = $store_phone;
// Adding Vendor Details admin shop_order pages
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
// Empty array
$shop_names = array();
// Output
echo '<h4>' . __( 'Store Name: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();
// NOT in array
if ( ! in_array( $shop_name, $shop_names ) ) {
// Push to array
$shop_names[] = $shop_name;
// Output
echo '<p>' . $shop_name . '</p>';
}
}
// Empty array
$store_phones = array();
// Output
echo '<h4>' . __( 'Seller Contact: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$store_phone = $vendor->get_phone();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $store_phone = dokan()->vendor->get( $author_id )->get_store_phone();
// NOT in array
if ( ! in_array( $store_phone, $store_phones ) ) {
// Push to array
$store_phones[] = $store_phone;
// Output
echo '<p>' . $store_phone . '</p>';
}
}
}
已测试并有效
我们想在订单管理订单详细信息页面中显示商店名称、供应商名称和供应商联系方式。
我正在使用
现在我们要显示供应商名称和供应商联系方式的详细信息。
Order Page Screenshot
我的尝试:
// Adding Vendor Details admin shop_order pages
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
// Empty array
$shop_names = array();
// Output
echo '<h4>' . __( 'Store Name: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();
// NOT in array
if ( ! in_array( $shop_name, $shop_names ) ) {
// Push to array
$shop_names[] = $shop_name;
// Output
echo '<p>' . $shop_name . '</p>';
}
}
// Empty array
$store_phones = array();
// Output
echo '<h4>' . __( 'Seller Contact: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$store_phone = $vendor->get_phone();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $store_phone = dokan()->vendor->get( $author_id )->get_store_phone();
// NOT in array
if ( ! in_array( $store_phone, $store_phones ) ) {
// Push to array
$store_phone[] = $store_phone;
// Output
echo '<p>' . $store_phone . '</p>';
}
}
}
通过使用此代码,我们获得了商店名称,但我们无法获得供应商名称和供应商联系方式。
您在此代码中的问题 $store_phone[] = $store_phone;
替换为 $store_phones[] = $store_phone;
// Adding Vendor Details admin shop_order pages
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
// Empty array
$shop_names = array();
// Output
echo '<h4>' . __( 'Store Name: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();
// NOT in array
if ( ! in_array( $shop_name, $shop_names ) ) {
// Push to array
$shop_names[] = $shop_name;
// Output
echo '<p>' . $shop_name . '</p>';
}
}
// Empty array
$store_phones = array();
// Output
echo '<h4>' . __( 'Seller Contact: ', 'woocommerce' ) . '</h4>';
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Author id
$author_id = $product->post->post_author;
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$store_phone = $vendor->get_phone();
// OR JUST USE THIS FOR SHOPNAME
// Shop name
// $store_phone = dokan()->vendor->get( $author_id )->get_store_phone();
// NOT in array
if ( ! in_array( $store_phone, $store_phones ) ) {
// Push to array
$store_phones[] = $store_phone;
// Output
echo '<p>' . $store_phone . '</p>';
}
}
}
已测试并有效