Advertisement
dgwatkins

Untitled

Feb 18th, 2019
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. function wpneo_crowdfunding_get_total_fund_raised_by_campaign($campaign_id = 0){
  2. global $wpdb, $post;
  3. $db_prefix = $wpdb->prefix;
  4.  
  5. if ($campaign_id == 0)
  6. $campaign_id = $post->ID;
  7.  
  8. // WPML compatibility.
  9. if ( apply_filters( 'wpml_setting', false, 'setup_complete' ) ) {
  10. $type = apply_filters( 'wpml_element_type', get_post_type( $campaign_id ) );
  11. $trid = apply_filters( 'wpml_element_trid', null, $campaign_id, $type );
  12. $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $type );
  13. $campaign_ids = wp_list_pluck( $translations, 'element_id' );
  14. } else {
  15. $campaign_ids = array( $campaign_id );
  16. }
  17. $placeholders = implode( ',', array_fill( 0, count( $campaign_ids ), '%d' ) );
  18.  
  19. $query = "SELECT
  20. SUM(ltoim.meta_value) as total_sales_amount
  21. FROM
  22. {$wpdb->prefix}woocommerce_order_itemmeta woim
  23. LEFT JOIN
  24. {$wpdb->prefix}woocommerce_order_items oi ON woim.order_item_id = oi.order_item_id
  25. LEFT JOIN
  26. {$wpdb->prefix}posts wpposts ON order_id = wpposts.ID
  27. LEFT JOIN
  28. {$wpdb->prefix}woocommerce_order_itemmeta ltoim ON ltoim.order_item_id = oi.order_item_id AND ltoim.meta_key = '_line_total'
  29. WHERE
  30. woim.meta_key = '_product_id' AND woim.meta_value IN ($placeholders) AND wpposts.post_status = 'wc-completed';";
  31.  
  32. $wp_sql = $wpdb->get_row($wpdb->prepare($query, $campaign_ids));
  33.  
  34. return $wp_sql->total_sales_amount;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement