Skip to content

Instantly share code, notes, and snippets.

@rickslayer
Last active April 14, 2023 12:16
Show Gist options
  • Save rickslayer/16e652be95f643a07fa07ef4e0783bf0 to your computer and use it in GitHub Desktop.
Save rickslayer/16e652be95f643a07fa07ef4e0783bf0 to your computer and use it in GitHub Desktop.
woocommerce_get_principal_user_data.sql
SELECT
wp_users.user_login as login,
wp_users.user_email as email,
firstmeta.meta_value as Nome,
lastmeta.meta_value as sobrenome,
shipping_citymeta.meta_value as cidade,
shipping_postcodemeta.meta_value as CEP,
shipping_statemeta.meta_value as UF,
shipping_phonemeta.meta_value as Telefone,
shipping_address_1meta.meta_value as Endereco,
shipping_address_2meta.meta_value as Endereco_2,
billing_cpfmeta.meta_value as CPF
FROM wp_users
left join wp_usermeta as firstmeta on wp_users.ID = firstmeta.user_id and firstmeta.meta_key = 'first_name'
left join wp_usermeta as lastmeta on wp_users.ID = lastmeta.user_id and lastmeta.meta_key = 'last_name'
left join wp_usermeta as shipping_citymeta on wp_users.ID = shipping_citymeta.user_id and shipping_citymeta.meta_key = 'shipping_city'
left join wp_usermeta as shipping_postcodemeta on wp_users.ID = shipping_postcodemeta.user_id and shipping_postcodemeta.meta_key = 'shipping_postcode'
left join wp_usermeta as shipping_statemeta on wp_users.ID = shipping_statemeta.user_id and shipping_statemeta.meta_key = 'shipping_state'
left join wp_usermeta as shipping_phonemeta on wp_users.ID = shipping_phonemeta.user_id and shipping_phonemeta.meta_key = 'shipping_phone'
left join wp_usermeta as shipping_address_1meta on wp_users.ID = shipping_address_1meta.user_id and shipping_address_1meta.meta_key = 'shipping_address_1'
left join wp_usermeta as shipping_address_2meta on wp_users.ID = shipping_address_2meta.user_id and shipping_address_2meta.meta_key = 'shipping_address_2'
left join wp_usermeta as billing_cpfmeta on wp_users.ID = billing_cpfmeta.user_id and billing_cpfmeta.meta_key = 'billing_cpf'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment