Remove add listing button, when one listing is created

hey,
hey,
is it possible to remove the ‘Add Listing’ button once the vendor has created their first listing? I want each vendor to have only one listing. Perhaps there’s a PHP snippet to hide the function altogether for vendors who already have a listing .

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

I’ve found a solution:

add_filter(
    'option_hp_listing_enable_submission',
    function( $value ) {
        if ( ! is_admin() && ! current_user_can( 'edit_posts' ) ) {
            return false;
        }

        // listing already done?
        $user_id = get_current_user_id(); // Benutzer-ID abrufen
        $listing_count = \HivePress\Models\Listing::query()->filter(
            [
                'status__in' => [ 'publish', 'pending', 'draft' ],
                'user'       => $user_id,
            ]
        )->get_count();

        if ( $listing_count >= 1 ) {
            return false; // do not display button
        }

        return $value;
    }
);

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