SELECT od.discount_amount as descuento_cupon, wco.ID as id_cupon, wco.post_title as cupon, wo.post_date as fecha, (SELECT meta_value from wp_postmeta where meta_key = 'rut' and post_id=wco.ID ) as rut, (SELECT meta_value from wp_postmeta where meta_key = '_billing_first_name' and post_id=wo.ID ) as nombre, (SELECT meta_value from wp_postmeta where meta_key = '_billing_last_name' and post_id=wo.ID ) as apellido, (SELECT meta_value from wp_postmeta where meta_key = '_order_total' and post_id=wo.ID ) as total_orden, (SELECT meta_value from wp_postmeta where meta_key = '_order_shipping' and post_id=wo.ID ) as precio_envio, ( select group_concat( order_item_name separator '
' ) from wp_woocommerce_order_items where order_id = wo.ID and order_item_type='line_item' ) as productos FROM wp_wc_order_coupon_lookup od INNER JOIN wp_posts wo ON od.order_id = wo.ID INNER JOIN wp_posts wco ON od.coupon_id = wco.ID WHERE wo.post_status IN ('wc-completed', 'wc-processing', 'wc-on-hold') AND wo.post_date >= '2019-05-05 10:00:00' AND wo.post_date <= '2021-02-27 21:00:00' ORDER BY wo.post_date ASC