LLMS_Course_Data::get_revenue( string $period )

Retrieve total amount of transactions related to orders for the course completed within the period


Parameters Parameters

$period

(string) (Required) Date period [current|previous].


Top ↑

Return Return

(float)


Top ↑

Source Source

File: includes/class.llms.course.data.php

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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( ',', $order_ids );
 
        global $wpdb;
        // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        $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' )
            )
        );// db call ok; no-cache ok.
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
 
        if ( is_null( $revenue ) ) {
            $revenue = 0;
        }
    }
 
    return apply_filters( 'llms_course_data_get_revenue', $revenue, $period, $this );
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.