LLMS_Membership_Data::get_revenue( string $period )
Retrieve total amount of transactions related to orders for the course completed within the period.
Parameters Parameters
- $period
-
(string) (Optional) Date period [current|previous]. Default 'current'.
Return Return
(float)
Source Source
File: includes/class.llms.membership.data.php
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | public function get_revenue( $period ) { $query = $this ->orders_query( -1 ); $order_ids = wp_list_pluck( $query ->posts, 'ID' ); $revenue = 0; if ( $order_ids ) { $order_ids = implode( ',' , array_map ( 'absint' , $order_ids ) ); global $wpdb ; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- ID list is sanitized via `absint()` earlier in this method. $revenue = $wpdb ->get_var( $wpdb ->prepare( "SELECT SUM( m2.meta_value ) FROM $wpdb ->posts AS p LEFT JOIN $wpdb ->postmeta AS m1 ON m1.post_id = p.ID AND m1.meta_key = '_llms_order_id' -- join for the ID LEFT JOIN $wpdb ->postmeta AS m2 ON m2.post_id = p.ID AND m2.meta_key = '_llms_amount' -- get the actual amounts WHERE p.post_type = 'llms_transaction' AND p.post_status = 'llms-txn-succeeded' AND m1.meta_value IN ({ $order_ids }) AND p.post_modified BETWEEN %s AND %s ;", $this ->get_date( $period , 'start' ), $this ->get_date( $period , 'end' ) ) ); // phpcs:enabled WordPress.DB.PreparedSQL.InterpolatedNotPrepared if ( is_null ( $revenue ) ) { $revenue = 0; } } return apply_filters( 'llms_membership_data_get_revenue' , $revenue , $period , $this ); } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.35.0 | Sanitize post ids from WP_Query before using for a new DB query. |
3.32.0 | Introduced. |