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. Default50. - '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()
- 'status'
Return Return
(array)
Source Source
File: includes/models/model.llms.order.php
* @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".
Expand full source code Collapse full source code View on GitHub
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. |