We want to show the vendor(s) from a order in the Admin order detail overview. We use some parts from the code below to display the vendor for each product in the invoice. Now we want to display which vendor are in the order actually for admin overview.
- If only items from one vendor is in the order => result: => Vendor(s): Vendor A
- If items from different vendors are in the order => result: => Vendor(s): Vendor A, Vendor B, Vendor C
This is what we have so far:
add_action( 'woocommerce_admin_order_data_after_billing_address', 'get_dokan_vendor_shop_name_from_order_test', 10, 1 );
function get_dokan_vendor_shop_name_from_order_test( $product_id ) {
if( empty($product_id) ) return;
$seller = get_post_field( 'post_author', $product_id );
$author = get_user_by( 'id', $seller );
$vendor = dokan()->vendor->get( $seller );
$store_info = dokan_get_store_info( $author->ID );
echo '<h4>' . __('TEST 1 - Vendor in order') . ' (' . $vendor->get_shop_name() . ')</h4>';
if ( ! empty( $store_info['store_name'] ) ) {
return $vendor->get_shop_name();
echo '<h4>' . __('TEST 2 - Vendor in order') . ' (' . $vendor->get_shop_name() . ')</h4>';
} else {
return;
}
}
UPDATE
With the new information, this is what we have so far: It displays the vendor but if a order has 2 items from vendor A, then it displays Vendor A three times.
So we now just have problems with the output. The vendor order infos are now available but the output is not the way we want that.
function action_woocommerce_admin_order_data_after_billing_address( $order ) {
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get product object
$product = $item->get_product();
// Seller
$seller = $product->post->post_author;
// Author
$author = get_user_by( 'id', $seller );
// Store info
$store_info = dokan_get_store_info( $author->ID );
// Vendor
$vendor = dokan()->vendor->get( $seller );
// Output Vendor in order - TEST 1
echo '<h4>' . __('TEST 2 - Vendor in order') . ' (' . $vendor->get_shop_name() . ')</h4>';
}
// Output Vendor in order - TEST 2
echo '<h4>' . __('TEST 2 - Vendor in order') . ' (' . $vendor->get_shop_name() . ')</h4>';
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
question from:
https://stackoverflow.com/questions/65901474/woocommerce-show-vendor-store-name-dokan-in-admin-order-details-overview 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…