LLMS_Order::get_transaction_total( string $type = 'amount' )
SQL query to retrieve total amounts for transactions by type
Parameters Parameters
- $type
-
(string) (Optional) Type can be 'amount' or 'refund_amount'. Default is 'amount'.
Default value: 'amount'
Return Return
(float)
Source Source
File: includes/models/model.llms.order.php
* @return float */ public function get_transaction_total( $type = 'amount' ) { $statuses = array( 'llms-txn-refunded' ); if ( 'amount' === $type ) { $statuses[] = 'llms-txn-succeeded'; } $post_statuses = ''; foreach ( $statuses as $i => $status ) { $post_statuses .= " p.post_status = '$status'"; if ( $i + 1 < count( $statuses ) ) { $post_statuses .= 'OR'; } } global $wpdb; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $post_statuses is prepared above. $grosse = $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 -- Join for the ID. LEFT JOIN $wpdb->postmeta AS m2 ON m2.post_id = p.ID -- Get the actual amounts. WHERE p.post_type = 'llms_transaction' AND ( $post_statuses ) AND m1.meta_key = %s AND m1.meta_value = %d AND m2.meta_key = %s ;", array( "{$this->meta_prefix}order_id", $this->get( 'id' ), "{$this->meta_prefix}{$type}", ) ) ); // db call ok; no-cache ok. // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.35.0 | Prepare SQL query properly. |
3.0.0 | Introduced. |