Wow thats honestly just refreshing to hear things are possible (and complex) I assumed they were. Not a developer myself, but after spending an embarrassing amount of money before giving up every developer I hired always needed to start from scratch nothing I ever had should have been added to because it would end up costing my users their privacy and eventually my entire site but if I spent just a little more they could build a complete working end product exactly what I wanted no problem. Easy and usually way quicker than I would’ve expected.
So thanks I sincerely appreciate it and I’m not sure if this helps, I had hoped there was a plugin making plugin to make it easy but ai made this, maybe it can be helpful I am not sure
Here’s an example of the code for a WordPress plugin that adds an “Available Now” feature to HivePress classifieds:
<?php
/*
Plugin Name: HivePress Available Now
Description: Enables the "Available Now" feature for HivePress classifieds.
Version: 1.0
Author: Your Name
*/
// Add custom meta field for "Available Now" feature
function hp_an_add_available_now_meta_field() {
hivepress()->listing->add_field(
'available_now',
[
'label' => __('Available Now', 'hivepress'),
'type' => 'checkbox',
'position' => 5,
'listing_types' => ['default'],
]
);
}
add_action('hp_init', 'hp_an_add_available_now_meta_field');
// Add "Available Now" badge to the listing card
function hp_an_add_available_now_badge($listing_id) {
$is_available_now = get_post_meta($listing_id, '_hp_available_now', true);
if ($is_available_now) {
echo '<span class="available-now-badge">Available Now</span>';
}
}
// Enable "Available Now" feature for vendors
function hp_an_enable_available_now_feature($listing) {
// Check if the user is a vendor
if (current_user_can('hp_vendor')) {
// Add "Available Now" checkbox to the listing form
hivepress()->listing->add_field(
'available_now',
[
'label' => __('Available Now', 'hivepress'),
'type' => 'checkbox',
'position' => 5,
'listing_types' => ['default'],
'editable' => true,
'visible' => true,
]
);
// Automatically turn off the "Available Now" feature after 4 hours
$expiration_time = 4 * 60 * 60; // 4 hours in seconds
if (isset($listing['available_now']) && $listing['available_now']) {
update_post_meta($listing['ID'], '_hp_available_now', true);
update_post_meta($listing['ID'], '_hp_available_now_expiration', time() + $expiration_time);
} else {
update_post_meta($listing['ID'], '_hp_available_now', false);
}
}
}
add_action('hp_save_listing', 'hp_an_enable_available_now_feature');
// Disable "Available Now" feature if time has expired
function hp_an_disable_available_now_feature($listing_id) {
$is_available_now = get_post_meta($listing_id, '_hp_available_now', true);
$expiration_time = get_post_meta($listing_id, '_hp_available_now_expiration', true);
if ($is_available_now && ($expiration_time <= time())) {
update_post_meta($listing_id, '_hp_available_now', false);
}
}
add_action('hp_save_listing', 'hp_an_disable_available_now_feature');
// Add custom CSS for "Available Now" badge
function hp_an_custom_css() {
echo '<style>.available-now-badge { background-color: #00ff00; color: #fff; padding: 5px;}</style>';
}
add_action('wp_head', 'hp_an_custom_css');
Please note that this code assumes you have the HivePress plugin installed and activated. Also, make sure to test the plugin thoroughly before deploying it on a live site.