Support » Plugin: WooCommerce » SKU in SQL statement

  • Resolved mosabua


    I have a custom plugin from a developer that is not available anymore and he wrote the following SQL query and now I should add the _sku to it. But I struggle to get it with all the left joins … So right now I get a result-list with product_id, post_title, date and quantity and now the resultlist should include the sku

    The SQL:

    SELECT PD.ID as product_id, PD.post_title,, SUM(ddo.quantity) as quantity FROM dckk0_daily_orders ddo 
            INNER JOIN 
            ( SELECT p.ID, p.post_title FROM dckk0_posts p LEFT JOIN dckk0_postmeta pm1 ON pm1.post_id = p.ID WHERE p.post_type in('product', 'product_variation') AND p.post_status = 'publish' GROUP BY p.ID,p.post_title ) AS PD ON PD.ID = ddo.product_id 
            INNER JOIN dckk0_posts p
            ON p.ID = ddo.order_id
            WHERE p.post_status in ('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed') AND >= DATE_FORMAT(CURDATE(),'%Y-%m-%d')
            GROUP BY PD.post_title,
            ORDER BY

    Thanks and any help would be awesome werner

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support gabrielfuentes


    Hi there šŸ‘‹

    This is a fairly complex development topic. Iā€™m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.


    Thread Starter mosabua


    Thanks for your links – after checking and re-thinking everthing I had an easier idea. I already have the id so I just used
    get_post_meta( $result->product_id, ‘_sku’, TRUE) in the loop and it works like a charm.

    Plugin Support gabrielfuentes


    That’s wonderful! šŸŽ‰

    Great! If you have any further questions, you can start a new thread.


Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.