LLMS_Product::has_active_subscriptions( boolean $use_cache = true )

Check if there are active subscriptions for this product.


Parameters Parameters

$use_cache

(boolean) (Optional) Whether or not leveraging the cache.

Default value: true


Top ↑

Return Return

(boolean)


Top ↑

Source Source

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

	public function has_active_subscriptions( $use_cache = true ) {

		$found = false;
		if ( $use_cache ) {
			$subscriptions_count = wp_cache_get( $this->get( 'id' ), 'llms_product_subscriptions_count', true, $found );
		}

		if ( false === $found ) {

			global $wpdb;

			$subscriptions_count = $wpdb->get_var(
				$wpdb->prepare(
					"
					SELECT COUNT(*) FROM {$wpdb->posts} as p
					JOIN {$wpdb->postmeta} as pm1
					JOIN {$wpdb->postmeta} as pm2
					WHERE p.ID=pm1.post_id
					AND p.post_type='llms_order'
					AND pm1.post_id=pm2.post_id
					AND pm1.meta_key='_llms_product_id' AND pm1.meta_value=%d
					AND pm2.meta_key='_llms_order_type' AND pm2.meta_value='recurring'
					AND p.post_status IN ( 'llms-active', 'llms-pending-cancel', 'llms-on-hold' )
					",
					$this->get( 'id' )
				)
			);

			wp_cache_set(
				$this->get( 'id' ),
				$subscriptions_count,
				'llms_product_subscriptions_count'
			);

		}

		return (bool) $subscriptions_count;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
5.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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