LLMS_Order::get_transaction_total( stirng $type = 'amount' )

SQL query to retrieve total amounts for transactions by type


Description Description


Parameters Parameters

$type

(stirng) (Optional) 'amount' or 'refund_amount'

Default value: 'amount'


Top ↑

Return Return

(float)


Top ↑

Source Source

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

	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;
		$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 = '{$this->meta_prefix}order_id'
			   AND m1.meta_value = %d
			   AND m2.meta_key = '{$this->meta_prefix}{$type}'
			;"
		, array( $this->get( 'id' ) ) ) );

		return floatval( $grosse );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: