Created
February 19, 2025 16:25
-
-
Save diogenesjup/089095d6ebed7ec6a9e514fb0a343b5c to your computer and use it in GitHub Desktop.
Exibir o nome do vendedor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Adiciona a coluna "Vendedor" na listagem de pedidos do WooCommerce | |
add_filter('manage_edit-shop_order_columns', 'adicionar_coluna_vendedor_pedidos'); | |
function adicionar_coluna_vendedor_pedidos($columns) { | |
$columns['vendedor'] = 'Vendedor'; | |
return $columns; | |
} | |
// Exibe o nome do vendedor salvo no meta_dado 'ident_vendedor' | |
add_action('manage_shop_order_posts_custom_column', 'mostrar_vendedor_pedido_lista', 10, 2); | |
function mostrar_vendedor_pedido_lista($column, $post_id) { | |
if ($column === 'vendedor') { | |
// Obtém o ID do vendedor salvo no meta_dado 'ident_vendedor' | |
$vendedor_id = get_post_meta($post_id, 'ident_vendedor', true); | |
if ($vendedor_id) { | |
$vendedor = get_userdata($vendedor_id); | |
if ($vendedor) { | |
echo esc_html($vendedor->display_name); | |
} else { | |
echo 'Usuário não encontrado'; | |
} | |
} else { | |
echo 'N/A'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment