LLMS_Order::get_transactions( array $args = array() )

Retrieve an array of transactions associated with the order according to supplied arguments


Parameters Parameters

$args

(array) (Optional) Hash of query argument data, ultimately passed to a WP_Query.

  • 'status'
    (string|string[]) Transaction post status or array of transaction post status. Defaults to "any".
  • 'type'
    (string|string[]) Transaction types or array of transaction types. Defaults to "any". Accepts "recurring", "single", or "trial".
  • 'per_page'
    (int) Number of transactions to include in the return. Default 50.
  • 'paged'
    (int) Result set page number.
  • 'order'
    (string) Result set order. Default "DESC". Accepts "DESC" or "ASC".
  • 'orderby'
    (string) Result set ordering field. Default "date".

Default value: array()


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/models/model.llms.order.php

1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
* @since 3.10.0 Unknown.
 * @since 3.37.6 Add additional return property, `total`, which returns the total number of found transactions.
 * @since 5.2.0 Use stric type comparisons.
 * @since 7.1.0 Added `no_found_rows` parameter.
 *
 * @param array $args {
 *     Hash of query argument data, ultimately passed to a WP_Query.
 *
 *     @type string|string[] $status        Transaction post status or array of transaction post status. Defaults to "any".
 *     @type string|string[] $type          Transaction types or array of transaction types. Defaults to "any".
 *                                          Accepts "recurring", "single", or "trial".
 *     @type int             $per_page      Number of transactions to include in the return. Default `50`.
 *     @type int             $paged         Result set page number.
 *     @type string          $order         Result set order. Default "DESC". Accepts "DESC" or "ASC".
 *     @type string          $orderby       Result set ordering field. Default "date".
 *     @type bool            $no_found_rows Whether to skip counting the total rows found. Enabling can improve
 *                                          performance. Default `false`.
 * }
 * @return array
 */
public function get_transactions( $args = array() ) {
 
    extract(
        wp_parse_args(
            $args,
            array(
                'status'        => 'any', // String or array or post statuses.
                'type'          => 'any', // String or array of transaction types [recurring|single|trial].
                'per_page'      => 50, // Int, number of transactions to return.
                'paged'         => 1, // Int, page number of transactions to return.
                'order'         => 'DESC',
                'orderby'       => 'date', // Field to order results by.
                'no_found_rows' => false,
            )
        )
    );
 
    // Assume any and use this to check for valid statuses.
    $statuses = llms_get_transaction_statuses();
 
    // Check statuses.
    if ( 'any' !== $statuses ) {
 
        // If status is a string, ensure it's a valid status.
        if ( is_string( $status ) && in_array( $status, $statuses, true ) ) {
            $statuses = array( $status );
        } elseif ( is_array( $status ) ) {
            $temp = array();
            foreach ( $status as $stat ) {
                if ( in_array( (string) $stat, $statuses, true ) ) {
                    $temp[] = $stat;
                }
            }
            $statuses = $temp;
        }
    }
 
    // Setup type meta query.
    $types = array(
        'relation' => 'OR',
    );
 
    if ( 'any' === $type ) {
        $types[] = array(
            'key'   => $this->meta_prefix . 'payment_type',
            'value' => 'recurring',
        );
        $types[] = array(
            'key'   => $this->meta_prefix . 'payment_type',
            'value' => 'single',
        );
        $types[] = array(
            'key'   => $this->meta_prefix . 'payment_type',
            'value' => 'trial',
        );
    } elseif ( is_string( $type ) ) {
        $types[] = array(
            'key'   => $this->meta_prefix . 'payment_type',
            'value' => $type,
        );
    } elseif ( is_array( $type ) ) {
        foreach ( $type as $t ) {
            $types[] = array(
                'key'   => $this->meta_prefix . 'payment_type',
                'value' => $t,
            );
        }
    }
 
    // Execute the query.
    $query = new WP_Query(
        /**
         * Filters the order's transactions query aguments.
         *
         * @since 3.0.0
         * @since 7.1.0 Added `$no_found_rows` arg.
         *
         * @param array $query_args {
         *     Hash of query argument data passed to a WP_Query.
         *
         *     @type string|string[] $status        Transaction post status or array of transaction post status.
         *                                          Defaults to "any".
         *     @type string|string[] $type          Transaction types or array of transaction types.
         *                                          Defaults to "any".
         *                                          Accepts "recurring", "single", or "trial".
         *     @type int             $per_page      Number of transactions to include in the return. Default `50`.
         *     @type int             $paged         Result set page number.
         *     @type string          $order         Result set order. Default "DESC". Accepts "DESC" or "ASC".


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Use stric type comparisons.
3.37.6 Add additional return property, total, which returns the total number of found transactions.
3.10.0 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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