Guest User

Untitled

a guest
Oct 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. /* OBTIENE LOS USUARIOS CON LA FACTURACIÓN Y DIRECCIONES */
  4. SELECT u.id, u.user_login, u.user_email,
  5.  
  6. max( CASE WHEN m.meta_key = 'billing_email' and u.ID = m.user_id THEN m.meta_value END ) as billing_email,
  7.  
  8. max( CASE WHEN m.meta_key = 'billing_first_name' and u.id = m.user_id THEN m.meta_value END ) as billing_first_name,
  9. max( CASE WHEN m.meta_key = 'billing_last_name' and u.id = m.user_id THEN m.meta_value END ) as billing_last_name,
  10. max( CASE WHEN m.meta_key = 'billing_address_1' and u.id = m.user_id THEN m.meta_value END ) as billing_address_1,
  11. max( CASE WHEN m.meta_key = 'billing_address_2' and u.id = m.user_id THEN m.meta_value END ) as billing_address_2,
  12. max( CASE WHEN m.meta_key = 'billing_city' and u.id = m.user_id THEN m.meta_value END ) as billing_city,
  13. max( CASE WHEN m.meta_key = 'billing_state' and u.id = m.user_id THEN m.meta_value END ) as billing_state,
  14. max( CASE WHEN m.meta_key = 'billing_postcode' and u.id = m.user_id THEN m.meta_value END ) as billing_postcode,
  15. max( CASE WHEN m.meta_key = 'shipping_first_name' and u.id = m.user_id THEN m.meta_value END ) as shipping_first_name,
  16. max( CASE WHEN m.meta_key = 'shipping_last_name' and u.id = m.user_id THEN m.meta_value END ) as shipping_last_name,
  17. max( CASE WHEN m.meta_key = 'shipping_address_1' and u.id = m.user_id THEN m.meta_value END ) as shipping_address_1,
  18. max( CASE WHEN m.meta_key = 'shipping_address_2' and u.id = m.user_id THEN m.meta_value END ) as shipping_address_2,
  19. max( CASE WHEN m.meta_key = 'shipping_city' and u.id = m.user_id THEN m.meta_value END ) as shipping_city,
  20. max( CASE WHEN m.meta_key = 'shipping_state' and u.id = m.user_id THEN m.meta_value END ) as _shipping_state,
  21. max( CASE WHEN m.meta_key = 'shipping_postcode' and u.id = m.user_id THEN m.meta_value END ) as _shipping_postcode
  22.  
  23. FROM wp_users u
  24. LEFT JOIN wp_usermeta m
  25. ON u.ID = m.user_id
  26. group by u.ID
  27.  
  28. /* OBTIENE LOS PRODUCTOS */
  29. SELECT product.ID as product_id, product.post_title as product_name, replace(product.post_content, '"', "'") as product_content, product_sku.meta_value as product_sku, product_price.meta_value as product_price, product_weight.meta_value as product_weight
  30. FROM wp_posts as product
  31. LEFT JOIN wp_postmeta as product_sku ON product.ID = product_sku.post_ID
  32. LEFT JOIN wp_postmeta as product_price ON product.ID = product_price.post_ID
  33. LEFT JOIN wp_postmeta as product_weight ON product.ID = product_weight.post_ID
  34. WHERE (product.post_type = 'product' OR product.post_type = 'product_variation') AND product_sku.meta_key = '_sku' AND product_price.meta_key = '_price' AND product_weight.meta_key = '_weight'
  35. ORDER BY product_id ASC
  36.  
  37. /* OBTIENE LOS PRODUCTOS CON PRECIO */
  38. SELECT p.id, p.post_title, m.meta_key, m.meta_value
  39. FROM wp_posts p
  40. INNER JOIN wp_postmeta m ON p.id=m.post_id
  41. AND m.meta_key='_price'
  42. AND m.meta_value = 0
  43.  
  44.  
  45. ?>
Add Comment
Please, Sign In to add comment