# How do I know which package a user is currently on?

**URL:** <https://community.hivepress.io/t/how-do-i-know-which-package-a-user-is-currently-on/14938>\
**Category:** Paid Listings\
**Created:** [February 8, 2025, 8:46pm UTC](https://community.hivepress.io/t/how-do-i-know-which-package-a-user-is-currently-on/14938 "2025-02-08T20:46:10Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![condorito.fr](https://community.hivepress.io/user_avatar/community.hivepress.io/condorito.fr/32/11449_2.png) [@condorito.fr](https://community.hivepress.io/u/condorito.fr)\
**Post date:** [February 8, 2025, 9:42pm UTC](https://community.hivepress.io/t/how-do-i-know-which-package-a-user-is-currently-on/14938/2 "2025-02-08T21:42:59Z")

</div>

For lack of a better solution, I return the last woocommerce order for that user.  
And rummage in the item (only one item/product per order in HivePress) for the given order to see if it has ‘premium-pack’ or ‘pro-pack’.

Updated code (for those who would be interested) :

```auto
function get_customer_orders_with_products() {
  
  $current_user = wp_get_current_user();
	$args = [
        'customer_id' => $current_user->ID,
        'limit' => 1, // just returns last order 
        'orderby' => 'date',
        'order' => 'DESC',
        'status' => ['wc-completed', 'wc-processing', 'wc-on-hold'], 
    ];

    $orders = wc_get_orders($args);
    
    foreach ($orders as $order) {
        foreach ($order->get_items() as $item) {
			$product = $item->get_product();
			if($product){//only one product per order anyway, so no need to loop endlessly
				return $product->get_slug(); //pro-pack or premium-pack (any other values not taken into account by CSS hack anyway)			
			}
        }
    }
}

/* ##############
* Add custom body class for package
*/
function add_custom_body_class_for_package($classes) {

	$result = get_customer_orders_with_products(); 
	if (!empty($result)) {
			$classes[] = $result; //add package name to body classes 
	}else{
			$classes[] ='no-package';		
	}    
    return $classes;
}
add_filter('body_class', 'add_custom_body_class_for_package');

```

Still, I don’t know if the plan is still current/valid, any suggestion welcome.

Not perfect, but good enough.

Cheers !

---

_[View the full topic](https://community.hivepress.io/t/how-do-i-know-which-package-a-user-is-currently-on/14938)._
