llms_locate_order_for_user_and_plan( int $user_id, int $plan_id )

Find an existing order for a given plan by a given user.

Parameters Parameters


(int) (Required) The WP_User ID.


(int) (Required) The Access Plan post ID.

Top ↑

Return Return

(mixed) null if no order found, WP_Post ID as an int if found

Top ↑

Source Source

File: includes/functions/llms.functions.order.php

function llms_locate_order_for_user_and_plan( $user_id, $plan_id ) {

	global $wpdb;

	// Query.
	$id = $wpdb->get_var(
			"SELECT ID FROM {$wpdb->prefix}posts AS p
			 JOIN {$wpdb->prefix}postmeta AS pm_user ON pm_user.post_id = p.ID AND pm_user.meta_key = '_llms_user_id'
			 JOIN {$wpdb->prefix}postmeta AS pm_plan ON pm_plan.post_id = p.ID AND pm_plan.meta_key = '_llms_plan_id'
			 WHERE p.post_type = 'llms_order'
			   AND pm_user.meta_value = %d
			   AND pm_plan.meta_value = %d
	); // db-cache ok.

	// Return an int not a numeric string.
	return $id ? absint( $id ) : $id;


Top ↑

Changelog Changelog

Version Description
3.30.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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