Advertisement
palsushobhan

show vendor name on order list

Jun 2nd, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. add_filter('wcfm_orders_additional_info_column_label', function ($column_label) {
  2.     if (current_user_can('administrator')) {
  3.         return 'Vendor';
  4.     }
  5.     return $column_label;
  6. });
  7.  
  8. add_filter('wcfm_orders_additonal_data_hidden', function ($is_allowed) {
  9.     if (current_user_can('administrator')) {
  10.         return false;
  11.     }
  12.     return true;
  13. });
  14.  
  15. add_filter('wcfm_orders_additonal_data', function ($column_data, $order_id) {
  16.     global $wpdb;
  17.     if (current_user_can('administrator')) {
  18.         $order = wc_get_order($order_id);
  19.         $items = $order->get_items('line_item');
  20.         $column_data_html = '';
  21.         $vendors = array();
  22.         foreach ($items as $order_item_id => $item) {
  23.             $line_item = new WC_Order_Item_Product($item);
  24.             $product_id = $line_item->get_product_id();
  25.             $vendor_id = wcfm_get_vendor_id_by_post($product_id);
  26.             if ($vendor_id && !in_array($vendor_id, $vendors)) {
  27.                 $vendors[] = $vendor_id;
  28.                 $store_user = wcfmmp_get_store($vendor_id);
  29.                 $column_data_html .= '<p>' . wcfm_get_vendor_store_name($vendor_id) . '</p>';
  30.             }
  31.         }
  32.         return $column_data_html;
  33.     }
  34.     return $column_data;
  35. }, 50, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement