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
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 | * @ 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. |