How to Manually Adjust Package Limit?

Hi,

To work around a current HivePress limitation, I’m trying to adjust the package limit in the database so that claimed listings count toward the package limit (e.g I will be importing listing and customer can claim listing and that should count toward their package limit). I understand HivePress doesn’t natively support this, so I’m open to manually updating the backend or database as needed.

I found that package data is stored in the wp_comments table, and I was able to locate my package. However, when I manually update the comment_karma value in the database, the change isn’t reflected in the UI. Interestingly, if I create a new listing, the comment_karma value decreases as expected in the database.

Could you clarify why my manual database changes aren’t updating the UI? Also, is there a recommended way to achieve this workaround, or an alternative approach that might help?

Thank you!

Hi,

Yes, you can change the number of packages on the database level; they are stored in comment_karma. As for the UI, it’s most likely caching, if you save objects through HivePress instead of manually, the cache will be refreshed. Alternatively, you can try disabling third-party plugins and cache using this PHP snippet: define(‘HP_CACHE’, false);

​I hope this is helpful to you.

Thank you! can you share how I can update this through hivepress?
What hook do I need to use to only update this when a claim is approved?

Here is my use case: I have a free package with 1 listing and a premium package with 10 listings. Claim is technically free but counts toward package limit.
So if a customer claim a listing and it is approved and they have the free package, their limit will decrease to 0, if they have the premium package their limit will decrease to 9.

Thanks!

Hi,

Unfortunately, claims are not counted in packages because there is no integration, and these are different monetization models. As a workaround, if you received notes that there was a claim, you can switch the listing to draft status and then publish it again (this should remove 1 from the limit), or to pending status and publish it again.

Hi,
I tried the workaround you suggested but it didn’t work.
Here is ma scenario: a user claimed a listing, i got a notification about the claim, I switched the listing status to draft and then publish, approved the claim, but the package limit is still 1. I also switched from pending to publish and got the same result. What am I missing? What i am trying to do it is make claimed listing counts toward the package limit.

Thanks

Hi,

Please make sure that you have accurately switched from draft status to publish because this is subject to one condition: hivepress-paid-listings/includes/components/class-listing-package.php at master · hivepress/hivepress-paid-listings · GitHub
Unfortunately, there is no other workaround, except for manual switching in the database, if this works for you, we can provide general guidance.

For anyone who might have the same requirement this is how I resolved it with a code snippet. This code snippet counts any claim toward packages limit and it creates a default package if customer doesn’t have a package assigned.

use HivePress\Models\Listing_Claim;
use HivePress\Models\User_Listing_Package;
use HivePress\Models\Listing_Package;

add_action('hivepress/v1/models/listing_claim/update_status', function($claim_id) {
	error_log('Updating package for claim started');
	
    // Validate the claim ID
    if (!is_numeric($claim_id) || $claim_id <= 0) {
        return;
    }

    // Fetch the claim object
    $claim = Listing_Claim::query()->get_by_id($claim_id);
    if (!$claim) {
        return;
    }

    // Check if the claim status is 'publish'
    if ($claim->get_status() !== 'publish') {
        return;
    }

    // Get the user ID from the claim
    $user_id = $claim->get_user__id();

    // Fetch user packages, ordered by submit limit (descending)
    $user_packages = User_Listing_Package::query()
        ->filter(['user' => $user_id])
        ->order(['submit_limit' => 'desc'])
        ->get();

    // Initialize user package
    $user_package = $user_packages ? reset($user_packages) : null;

    // If no user package found, assign a default free package
    if (!$user_package) {
        $default_free_package_id = YOUR_DEFAULT_PACKAGE_ID_HERE;
        $package = Listing_Package::query()->get_by_id($default_free_package_id);

        if (!$package || $package->get_status() !== 'publish') {
            return;
        }

        // Create a new user package
        $user_package = (new User_Listing_Package())->fill(
            array_merge(
                $package->serialize(),
                [
                    'user'    => $user_id,
                    'package' => $package->get_id(),
                    'default' => true,
                ]
            )
        );

        // Save the new user package
        if (!$user_package->save()) {
            return;
        }
    }

    // Reduce the submit limit if greater than 0
    if ($user_package->get_submit_limit() > 0) {
        $user_package->set_submit_limit($user_package->get_submit_limit() - 1)->save();
		error_log('Updating package for claim successful');
    }
});

Also if anyone has any feedback on this code, please let me know :slight_smile:

1 Like

Hi,

Thank you for the solution, it will be useful for our community.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.