Specific Staff Shortcode

πŸ‘ Gathering votes

Use a shortcode to pre-choose a staff member, so the user won't have to choose a staff member.
Basically admin will be able to choose a staff member for the user.
Use cases: we can embed the shortcode in a staff member profile page.

For example: [bookingpress_form staff=1] [bookingpress_form staff=2] [bookingpress_form staff=3], etc...

Creosmart

1 year ago

Activity
Niyaemilov

I've gone withh creating a small plugin for this (all reviews)

<?php
/*
Plugin Name: Staff Reviews
Description: Displays staff reviews in a grid layout with star ratings.
Version: 1.0
Author: Name
*/

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Define constants
define('STAFF_REVIEWS_LIMIT', 25); // Number of reviews to display
define('STAFF_REVIEWS_TABLE', 'bookingpress_staff_review'); // Database table name

// Enqueue CSS
function staff_reviews_enqueue_styles() {
    wp_enqueue_style(
        'staff-reviews-css',
        plugin_dir_url(__FILE__) . 'assets/css/staff-reviews.css',
        array(), // No dependencies
        filemtime(plugin_dir_path(__FILE__) . 'assets/css/staff-reviews.css') // Version based on file modification time
    );
}
add_action('wp_enqueue_scripts', 'staff_reviews_enqueue_styles');

// Shortcode function
function staff_reviews_shortcode() {
    global $wpdb;

    // Fetch reviews
    $table_name = $wpdb->prefix . STAFF_REVIEWS_TABLE;
    $reviews = $wpdb->get_results($wpdb->prepare("
        SELECT bookingpress_customer_name, review_rating, review_title, review_comment, updated_at
        FROM $table_name
        ORDER BY updated_at DESC
        LIMIT %d
    ", STAFF_REVIEWS_LIMIT));

    // Error handling
    if (is_wp_error($reviews)) {
        return '<p class="staff-reviews-error">Π“Ρ€Π΅ΡˆΠΊΠ° ΠΏΡ€ΠΈ Π·Π°Ρ€Π΅ΠΆΠ΄Π°Π½Π΅ Π½Π° Ρ€Π΅Π²ΡŽΡ‚Π°.</p>';
    }

    if (empty($reviews)) {
        return '<p class="staff-reviews-notice">Няма Π½Π°Π»ΠΈΡ‡Π½ΠΈ Ρ€Π΅Π²ΡŽΡ‚Π°.</p>';
    }

    // Build output
    $output = '<div class="staff-reviews-grid">';
    foreach ($reviews as $review) {
        $output .= '<div class="staff-review-card">';
        $output .= '<div class="staff-review-header">';
        $output .= '<h3 class="staff-review-author">' . esc_html($review->bookingpress_customer_name) . '</h3>';
        $output .= '<div class="staff-star-rating">';

        // Generate star rating
        $rating = intval($review->review_rating);
        for ($i = 1; $i <= 5; $i++) {
            $output .= $i <= $rating
                ? '<span class="staff-star filled">β˜…</span>'
                : '<span class="staff-star">β˜†</span>';
        }

        $output .= '</div></div>'; // Close star rating and header
        $output .= '<h4 class="staff-review-title">' . esc_html($review->review_title) . '</h4>';
        $output .= '<p class="staff-review-comment">' . esc_html($review->review_comment) . '</p>';
        $output .= '<time class="staff-review-date">' . esc_html(date('j/m/Y', strtotime($review->updated_at))) . '</time>';
        $output .= '</div>'; // Close review card
    }
    $output .= '</div>'; // Close grid

    return $output;
}
add_shortcode('staff_reviews', 'staff_reviews_shortcode');

0    1 month ago    Reply

Comment must be at least 20 characters.
Cancel

We love to listen to our customers.

Hamrahcare

It's very needed for services like therapy that the therapist doesn't change through the process.

0    2 months ago    Reply

Comment must be at least 20 characters.
Cancel

We love to listen to our customers.

Categories
πŸŽ‰ Feature