Advanced_Coupons_Helpers::get_total_credits_of_the_user( $user_id )

Get customer’s lifetime store credit balance


Source

File: src/integrations/advanced-coupons/helpers/advanced-coupons-helpers.php

	public function get_total_credits_of_the_user( $user_id ) {
		global $wpdb;
		$raw_data = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT entry_type,entry_action,CONVERT(entry_amount, DECIMAL(%d,%d)) AS amount
                FROM {$wpdb->prefix}acfw_store_credits
                WHERE user_id = %d",
				\ACFWF()->Store_Credits_Calculate->get_decimal_precision(),
				wc_get_price_decimals(),
				$user_id
			),
			ARRAY_A
		);
		$total_amount = 0;
		foreach ( $raw_data as $value ) {
			if ( isset( $value['entry_type'] ) && 'increase' === $value['entry_type'] ) {
				$total_amount += floatval( $value['amount'] );
			}
		}
		return apply_filters( 'acfw_filter_amount', $total_amount );
	}