We add vendor information in the admin order details for each order via:
Now I also want to add this information also in the order preview. I found this answer
We change the hook to woocommerce_admin_order_preview_end
but now when we want to open the preview nothing happend.
Do we have to adjust the whole code in order that it works for the order preview or why is our approach not working?
function action_woocommerce_admin_order_vendor_data( $order ) {
// Empty array
$shop_names = array();
// Output
echo '<strong>' . __( 'Vendor(s): ', 'woocommerce' ) . '</strong>';
// 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 $shop_name . ', ';
}
}
}
add_action('woocommerce_admin_order_preview_end', 'action_woocommerce_admin_order_vendor_data', 10, 1 );