HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/doccure-wp/wp-content/plugins/doccure-elementor/widgets/class-doctors-carousel.php
<?php
/**
 * Awesomesauce class.
 *
 * @category   Class
 * @package    ElementorAwesomesauce
 * @subpackage WordPress
 * @author     Ben Marshall <[email protected]>
 * @copyright  2020 Ben Marshall
 * @license    https://opensource.org/licenses/GPL-3.0 GPL-3.0-only
 * @link       link(https://www.benmarshall.me/build-custom-elementor-widgets/,
 *             Build Custom Elementor Widgets)
 * @since      1.0.0
 * php version 7.3.9
 */

namespace ElementorDoccure\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Utils;

if ( ! defined( 'ABSPATH' ) ) {
	// Exit if accessed directly.
	exit;
}

/**
 * Awesomesauce widget class.
 *
 * @since 1.0.0
 */
class DoctorsCarousel extends Widget_Base {

	/**
	 * Retrieve the widget name.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'DoctorsCarousel';
	}

	/**
	 * Retrieve the widget title.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Doctors Carousel', 'doccure_elementor' );
	}

	/**
	 * Retrieve the widget icon.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-carousel-loop';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	 *
	 * Used to determine where to display the widget in the editor.
	 *
	 * Note that currently Elementor supports only one category.
	 * When multiple categories passed, Elementor uses the first one.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return array( 'doccure' );
	}

	/**
	 * Register the widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function _register_controls() {
		$categories	= elementor_get_taxonomies('doctors','specialities');
		$categories	= !empty($categories) ? $categories : array();
		//Content
		$this->start_controls_section(
			'content_section',
			[
				'label' => esc_html__( 'Content', 'doccure_elementor' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);
		
		$this->add_control(
			'style',
			[
				'label' => __( 'Style ', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'style1',
				'options' => [
					'style_main' =>  __( 'Style Main', 'doccure_elementor' ),
					'style1' =>  __( 'Style 1', 'doccure_elementor' ),
					'style2' =>  __(  'Style 2 ', 'doccure_elementor' ),
					'style3'=>  __(  'Style 3', 'doccure_elementor' ),
					'style4'=>  __(  'Style 4', 'doccure_elementor' ),
					'style5'=>  __(  'Style 5', 'doccure_elementor' ),
  				],
			]
		);

		$this->add_control(
			'title',
			array(
				'label'   => __( 'Title', 'doccure_elementor' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'Title', 'doccure_elementor' ),
				'condition' => [
					'style' => [ 'style_main','style5'], 
				],
			)
		);	
		$this->add_control(
			'subtitle',
			array(
				'label'   => __( 'Sub-Title', 'doccure_elementor' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'Title', 'doccure_elementor' ),
				'condition' => [
					'style' => [ 'style5'], 
				],
			)
		);	

		$this->add_control(
			'limit',
			[
				'label' => __( 'Doctors to display', 'doccure_elementor' ),
				'type' => \Elementor\Controls_Manager::NUMBER,
				'min' => 1,
				'max' => 50,
				'step' => 1,
				'default' => 4,
			]
		);
 
		$this->add_control(
			'orderby',
			[
				'label' => __( 'Order by', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'date',
				'options' => [
					'none' =>  __( 'No order', 'doccure_elementor' ),
					'ID' =>  __(  'Order by post id. ', 'doccure_elementor' ),
					'author'=>  __(  'Order by author.', 'doccure_elementor' ),
					'title' =>  __(  'Order by title.', 'doccure_elementor' ),
					'name' =>  __( ' Order by post name (post slug).', 'doccure_elementor' ),
					'type'=>  __( ' Order by post type.', 'doccure_elementor' ),
					'date' =>  __( ' Order by date.', 'doccure_elementor' ),
					'modified' =>  __( ' Order by last modified date.', 'doccure_elementor' ),
					'parent' =>  __( ' Order by post/page parent id.', 'doccure_elementor' ),
					'rand' =>  __( ' Random order.', 'doccure_elementor' ),
					'comment_count' =>  __( ' Order by number of comments', 'doccure_elementor' ),
					'subscription' =>  __( ' Order by subscription status', 'doccure_elementor' ),
					'menu_order' =>  __( ' Order by menu order', 'doccure_elementor' ),
				],
			]
		);
		
		$this->add_control(
			'order',
			[
				'label' => __( 'Order', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'DESC',
				'options' => [
					'DESC' =>  __( 'Descending', 'doccure_elementor' ),
					'ASC' =>  __(  'Ascending', 'doccure_elementor' ),
				],
			]
		);

		$this->add_control(
			'show_subscription_badge',
			[
				'label' => __( 'Show Subscription Badge', 'doccure_elementor' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => __( 'Show', 'doccure_elementor' ),
				'label_off' => __( 'Hide', 'doccure_elementor' ),
				'return_value' => 'yes',
				'default' => 'no',
				'description' => __( 'Display a badge for doctors with active subscriptions', 'doccure_elementor' ),
			]
		);

		$this->add_control(
			'link',
			array(
				'label'   => __( 'Link', 'doccure_elementor' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => '',
			)
		);
					
		$this->end_controls_section();
	}

	/**
	 * Check if doctor has active subscription using dc_subscription meta data
	 */
	private function has_active_subscription($doctor_id) {
		// Get the user ID from doctor post (author ID)
		$author_id = get_post_field('post_author', $doctor_id);
		if (empty($author_id)) {
			return false;
		}

		$current_time = current_time('timestamp');

		
	
		
		// First, check if user has subscription using doccure function (most reliable)
		if (function_exists('doccure_get_subscription_metadata')) {
			$subscription_package_string = doccure_get_subscription_metadata('subscription_package_string', intval($author_id));
			
			if ($subscription_package_string !== false && $subscription_package_string > $current_time) {
				
				return true;
			}
		}
		print_r($subscription_package_string);
		
		// Check dc_subscription meta key (serialized array)
		$dc_subscription = get_user_meta($author_id, 'dc_subscription', true);
		
		if (!empty($dc_subscription)) {
			// It might be a serialized string - try to unserialize it
			$subscription_data = $dc_subscription;
			
			if (is_string($dc_subscription)) {
				$subscription_data = @unserialize($dc_subscription);
			}
			
			// Check if we have valid subscription data
			if (is_array($subscription_data)) {
				// Check subscription_package_string (timestamp)
				if (isset($subscription_data['subscription_package_string'])) {
					$expiry_timestamp = $subscription_data['subscription_package_string'];
					if ($expiry_timestamp > $current_time) {
						
					}
				}
				return true;
				
				// Also check subscription_package_expiry (datetime string)
				if (isset($subscription_data['subscription_package_expiry'])) {
					$expiry_timestamp = strtotime($subscription_data['subscription_package_expiry']);
					if ($expiry_timestamp > $current_time) {
					
					}
				}
				print_r($expiry_timestamp);	
				
				// Check subscription_id - if it exists, user has a subscription
				if (isset($subscription_data['subscription_id']) && !empty($subscription_data['subscription_id'])) {
					// We need to check if it's expired
					if (isset($subscription_data['subscription_package_string'])) {
						$expiry_timestamp = $subscription_data['subscription_package_string'];
						if ($expiry_timestamp > $current_time) {
							return true;
						}
					} elseif (isset($subscription_data['subscription_package_expiry'])) {
						$expiry_timestamp = strtotime($subscription_data['subscription_package_expiry']);
						if ($expiry_timestamp > $current_time) {
							return true;
						}
					} else {
						// If we have subscription_id but no expiry, assume it's active
						return true;
					}
				}
			}
		}
		
		// Fallback: check if subscription_package meta exists (for backward compatibility)
		$subscription_package = get_user_meta($author_id, 'subscription_package', true);
		if (!empty($subscription_package)) {
			// Check if subscription has expiry
			$subscription_expiry = get_user_meta($author_id, 'subscription_expiry', true);
			if (!empty($subscription_expiry)) {
				$expiry_timestamp = is_numeric($subscription_expiry) ? $subscription_expiry : strtotime($subscription_expiry);
				if ($expiry_timestamp > $current_time) {
					return true;
				}
			} else {
				// If no expiry but has subscription, consider it active
				return true;
			}
		}
		
		return false;
	}

	/**
	 * Get subscription package name for a doctor
	 */
	private function get_subscription_package_name($doctor_id) {
		$author_id = get_post_field('post_author', $doctor_id);
		if (empty($author_id)) {
			return '';
		}

		// First try to get package name from subscription_id in dc_subscription
		$dc_subscription = get_user_meta($author_id, 'dc_subscription', true);
		
		if (!empty($dc_subscription)) {
			$subscription_data = $dc_subscription;
			
			if (is_string($dc_subscription)) {
				$subscription_data = @unserialize($dc_subscription);
			}
			
			if (is_array($subscription_data) && isset($subscription_data['subscription_id'])) {
				// Try to get the product/post title from subscription_id
				$subscription_id = $subscription_data['subscription_id'];
				$package_title = get_the_title($subscription_id);
				
				if (!empty($package_title) && $package_title != 'Auto Draft') {
					return $package_title;
				}
			}
		}
		
		// Fallback: check subscription_package meta
		$subscription_package = get_user_meta($author_id, 'subscription_package', true);
		if (!empty($subscription_package)) {
			$package_title = get_the_title($subscription_package);
			if (!empty($package_title) && $package_title != 'Auto Draft') {
				return $package_title;
			}
		}
		
		return __('Premium Package', 'doccure_elementor');
	}

	/**
	 * Get subscription expiry date for a doctor
	 */
	private function get_subscription_expiry_date($doctor_id) {
		$author_id = get_post_field('post_author', $doctor_id);
		if (empty($author_id)) {
			return '';
		}

		$current_time = current_time('timestamp');
		
		// First try doccure function
		if (function_exists('doccure_get_subscription_metadata')) {
			$subscription_package_string = doccure_get_subscription_metadata('subscription_package_string', intval($author_id));
			
			if ($subscription_package_string !== false && $subscription_package_string > $current_time) {
				return date_i18n(get_option('date_format'), $subscription_package_string);
			}
		}
		
		// Check dc_subscription meta
		$dc_subscription = get_user_meta($author_id, 'dc_subscription', true);
		
		if (!empty($dc_subscription)) {
			$subscription_data = $dc_subscription;
			
			if (is_string($dc_subscription)) {
				$subscription_data = @unserialize($dc_subscription);
			}
			
			if (is_array($subscription_data)) {
				// Check subscription_package_string (timestamp)
				if (isset($subscription_data['subscription_package_string'])) {
					$expiry_timestamp = $subscription_data['subscription_package_string'];
					if ($expiry_timestamp > $current_time) {
						return date_i18n(get_option('date_format'), $expiry_timestamp);
					}
				}
				
				// Also check subscription_package_expiry (datetime string)
				if (isset($subscription_data['subscription_package_expiry'])) {
					$expiry_timestamp = strtotime($subscription_data['subscription_package_expiry']);
					if ($expiry_timestamp > $current_time) {
						return date_i18n(get_option('date_format'), $expiry_timestamp);
					}
				}
			}
		}
		
		// Fallback: check subscription_expiry meta
		$subscription_expiry = get_user_meta($author_id, 'subscription_expiry', true);
		if (!empty($subscription_expiry)) {
			$expiry_timestamp = is_numeric($subscription_expiry) ? $subscription_expiry : strtotime($subscription_expiry);
			if ($expiry_timestamp > $current_time) {
				return date_i18n(get_option('date_format'), $expiry_timestamp);
			}
		}
		
		return '';
	}

	/**
	 * Get doctors sorted by subscription status
	 */
	private function get_doctors_sorted_by_subscription($limit, $order) {
		// Get all doctors
		$args = array(
			'post_type' => 'doctors',
			'post_status' => 'publish',
			'posts_per_page' => -1,
		);
		
		$all_doctors = get_posts($args);
		
		// Separate doctors with and without subscriptions
		$doctors_with_subscription = array();
		$doctors_without_subscription = array();
		
		foreach ($all_doctors as $doctor) {
			if ($this->has_active_subscription($doctor->ID)) {
				$doctors_with_subscription[] = $doctor;
			} else {
				$doctors_without_subscription[] = $doctor;
			}
		}
		
		// Apply ordering
		if ($order === 'DESC') {
			// Subscription doctors first, then non-subscription
			$sorted_doctors = array_merge($doctors_with_subscription, $doctors_without_subscription);
		} else {
			// Non-subscription doctors first, then subscription
			$sorted_doctors = array_merge($doctors_without_subscription, $doctors_with_subscription);
		}
		
		// Limit to requested number
		if ($limit > 0) {
			$sorted_doctors = array_slice($sorted_doctors, 0, $limit);
		}
		
		return $sorted_doctors;
	}

	/**
	 * Get doctors with regular ordering
	 */
	private function get_doctors_with_regular_order($limit, $orderby, $order) {
		$args = array(
			'post_type' => 'doctors',
			'post_status' => 'publish',
			'posts_per_page' => $limit,
			'orderby' => $orderby,
			'order' => $order,
		);
		
		return get_posts($args);
	}

	/**
	 * Get doctor speciality
	 */
	private function get_doctor_speciality($doctor_id) {
		$author_id = get_post_field('post_author', $doctor_id);
		$spe_service_id = get_user_meta($author_id, 'spe_service', true); 
		
		if (!empty($spe_service_id)) {
			$taxonomy = 'specialities';
			$term = get_term($spe_service_id, $taxonomy);
			
			if (!is_wp_error($term) && !empty($term)) {
				return $term->name;
			}
		}
		
		// Fallback: get first speciality term from doctor post
		$terms = wp_get_post_terms($doctor_id, 'specialities');
		if (!is_wp_error($terms) && !empty($terms)) {
			return $terms[0]->name;
		}
		
		return '';
	}

	/**
	 * Render the widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function render() { 
		$settings = $this->get_settings_for_display();
 		$limit = $settings['limit'] ? $settings['limit'] : 4;
		$orderby = $settings['orderby'] ? $settings['orderby'] : 'date';
		$order = $settings['order'] ? $settings['order'] : 'DESC';
		$show_subscription_badge = $settings['show_subscription_badge'] === 'yes';

		// Get doctors based on orderby selection
		if ($orderby === 'subscription') {
			$my_query = $this->get_doctors_sorted_by_subscription($limit, $order);
		} else {
			$my_query = $this->get_doctors_with_regular_order($limit, $orderby, $order);
		}

		// Check if no doctors found
		if (empty($my_query)) {
			echo '<div class="alert alert-info">' . esc_html__('No doctors found.', 'doccure_elementor') . '</div>';
			return;
		}

		// Add subscription badge CSS if enabled
		if ($show_subscription_badge) {
			echo '<style>
				.subscription-badge {
					position: absolute;
					top: 10px;
					right: 10px;
					background: linear-gradient(45deg, #FFD700, #FFA500);
					color: #000;
					padding: 3px 8px;
					border-radius: 12px;
					font-size: 10px;
					font-weight: bold;
					z-index: 10;
					box-shadow: 0 2px 5px rgba(0,0,0,0.2);
				}
				.subscription-badge i {
					margin-right: 3px;
				}
				.doctor-profile-widget, .doccure_doctor-thumb, .best-doctor-image, .best-doctors-img, .card-img-hover {
					position: relative;
				}
				.subscription-indicator {
					display: inline-block;
					color: #FFA500;
					font-size: 12px;
					margin-left: 5px;
				}
				.subscription-indicator i {
					margin-right: 3px;
				}
			</style>';
		}

		// Display doctors based on selected style
		if($settings['style']=='style_main') { ?>
			<div class="container">
				<div class="row">
					<div class="col-md-6 aos" data-aos="fade-up">
						<div class="section-header-one section-header-slider">
							<h2 class="section-title"><?php echo esc_html($settings['title']); ?></h2>
						</div>
					</div>
					<div class="col-md-6 aos" data-aos="fade-up">
						<div class="owl-nav slide-nav-2 text-end nav-control"></div>
					</div>
				</div>
				<div class="owl-carousel doctor-slider-one owl-theme aos" data-aos="fade-up">
					<?php 
					$counter = 0;
					foreach($my_query as $doctor): 
						$counter++;
						$doctor_id = $doctor->ID;
						$has_subscription = $this->has_active_subscription($doctor_id);
						$subscription_package_name = $this->get_subscription_package_name($doctor_id);
						
						// Get doctor image
						if (has_post_thumbnail($doctor_id)) {
							$url = get_the_post_thumbnail_url($doctor_id, 'medium');
						} else {
							$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
						}
						
						// Get doctor data
						$feedback = get_post_meta($doctor_id, 'review_data', true);
						$feedback = !empty($feedback) ? $feedback : array();
						$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
						$dc_average_rating = !empty($feedback['dc_average_rating']) ? $feedback['dc_average_rating'] : 0;
						$name = doccure_full_name($doctor_id);
						$name = !empty($name) ? $name : '';
						$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
						$speciality = $this->get_doctor_speciality($doctor_id);
					?>
					<div class="item">
						<div class="doctor-profile-widget">
							<div class="doc-pro-img">
								<a href="<?php echo get_permalink($doctor_id); ?>">
									<div class="doctor-profile-img">
										<img src="<?php echo esc_url($url); ?>" class="img-fluid" alt="<?php echo esc_attr($name); ?>"/>
										<?php if ($show_subscription_badge && $has_subscription): ?>
											<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
												<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
											</div>
										<?php endif; ?>
									</div>
								</a>
								<div class="doctor-amount">
									<span><?php doccure_price_format($starting_price); ?></span>
								</div>
							</div>
							<div class="doc-content">
								<div class="doc-pro-info pb-0">
									<div class="doc-pro-name">
										<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
										<?php if (!empty($speciality)): ?>
											<a href="#"><p><?php echo esc_html($speciality); ?></p></a>
										<?php endif; ?>
										<?php if ($has_subscription && !empty($subscription_package_name)): ?>
											<span class="subscription-indicator">
												<i class="fas fa-star"></i> <?php echo esc_html($subscription_package_name); ?>
											</span>
										<?php endif; ?>
									</div>
									<div class="reviews-ratings">
										<p>
											<span><i class="fas fa-star"></i><?php echo esc_html($dc_average_rating); ?></span>
											(<?php echo esc_html($total_rating); ?>)
										</p>
									</div>
								</div>
							</div>
						</div>
					</div>
					<?php endforeach; ?>
				</div>
			</div>

		<?php } else if($settings['style']=='style1') { ?>
			<div class="home_doctor_slider row">
				<?php 
				$counter = 0;
				foreach ($my_query as $my_querys):
					$counter++;
					$doctor_id = $my_querys->ID;
					$has_subscription = $this->has_active_subscription($doctor_id);
					$subscription_package_name = $this->get_subscription_package_name($doctor_id);
					
					// Get doctor image
					if (has_post_thumbnail($doctor_id)) {
						$url = get_the_post_thumbnail_url($doctor_id, 'medium');
					} else {
						$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
					}
					
					// Get doctor data
					$feedback = get_post_meta($doctor_id, 'review_data', true);
					$feedback = !empty($feedback) ? $feedback : array();
					$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
					$total_percentage = !empty($feedback['dc_total_percentage']) ? $feedback['dc_total_percentage'] : 0;
					$name = doccure_full_name($doctor_id);
					$name = !empty($name) ? $name : '';
					$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
					$speciality = $this->get_doctor_speciality($doctor_id);
				?>
				<div class="col-xl-4 col-lg-6 col-md-6 col-sm-12">
					<div class="col-lg-12">
						<div class="doccure_doctor-thumb doccure-filter-img-wrapper">
							<img src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($name); ?>"/>
							<?php if ($show_subscription_badge && $has_subscription): ?>
								<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
									<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
								</div>
							<?php endif; ?>
						</div>
					</div>
					<div class="col-lg-12">
						<div class="doccure_doctor-body">
							<h5>
								<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
								<?php if ($has_subscription && !empty($subscription_package_name)): ?>
									<span class="subscription-indicator">
										<i class="fas fa-star"></i> <?php echo esc_html($subscription_package_name); ?>
									</span>
								<?php endif; ?>
							</h5>
							<?php if (!empty($speciality)): ?>
								<p class="doctor-speciality"><?php echo esc_html($speciality); ?></p>
							<?php endif; ?>
							<div class="ratings">
								<div class="empty-stars"></div>
								<div class="full-stars" style="width: <?php echo intval($total_percentage); ?>%"></div>
							</div>
							
							<?php if(!empty($starting_price)): ?>
								<div class="price-section">
									<i class="far fa-money-bill-alt"></i>&nbsp; <?php doccure_price_format($starting_price); ?>
								</div>
							<?php endif; ?>
							
							<div id="button-widget" class="chw-widget-area widget-area" role="complementary">
								<div class="row row-sm mt-3">
									<div class="col-6">
										<a href="<?php echo get_permalink($doctor_id); ?>">
											<button class="view-btn" tabindex="0"><?php esc_html_e('View Profile', 'doccure_elementor'); ?></button>
										</a>
									</div>
									<div class="col-6">
										<a href="<?php echo esc_url(site_url('/book-appointment/?doctor=' . intval($doctor_id))); ?>">
											<button class="book-btn" tabindex="0"><?php esc_html_e('Book Now', 'doccure_elementor'); ?></button>
										</a>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php endforeach; ?>
			</div>

		<?php } else if($settings['style']=='style2') { ?>
			<div class="doctor-book-slider">
				<?php 
				$counter = 0;
				foreach($my_query as $doctor):
					$counter++;
					$doctor_id = $doctor->ID;
					$has_subscription = $this->has_active_subscription($doctor_id);
					$subscription_package_name = $this->get_subscription_package_name($doctor_id);
					
					// Get doctor image
					if (has_post_thumbnail($doctor_id)) {
						$url = get_the_post_thumbnail_url($doctor_id, 'medium');
					} else {
						$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
					}
					
					// Get doctor data
					$feedback = get_post_meta($doctor_id, 'review_data', true);
					$feedback = !empty($feedback) ? $feedback : array();
					$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
					$total_percentage = !empty($feedback['dc_total_percentage']) ? $feedback['dc_total_percentage'] : 0;
					$name = doccure_full_name($doctor_id);
					$name = !empty($name) ? $name : '';
					$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
					$speciality = $this->get_doctor_speciality($doctor_id);
				?>
				<div>
					<div class="doctor-profile-widget">
						<a href="<?php echo get_permalink($doctor_id); ?>">
							<img class="home2_doctor_img" src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($name); ?>"/>
							<?php if ($show_subscription_badge && $has_subscription): ?>
								<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
									<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
								</div>
							<?php endif; ?>
						</a>
						<div class="pro-content">
							<div class="provider-info">
								<div class="pro-icon">
									<img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon2.png" alt="icon"/>
								</div>
								<h3 class="mb-1">
									<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
									<?php do_action('doccure_get_doctorverification_check', $doctor_id, ''); ?>
									<?php if ($has_subscription && !empty($subscription_package_name)): ?>
										<span class="subscription-indicator">
											<i class="fas fa-star"></i> <?php echo esc_html($subscription_package_name); ?>
										</span>
									<?php endif; ?>
								</h3>
								
								<?php if (!empty($speciality)): ?>
									<a href="#"><p><?php echo esc_html($speciality); ?></p></a>
								<?php endif; ?>
								
								<div class="ratings">
									<div class="empty-stars"></div>
									<div class="full-stars" style="width: <?php echo intval($total_percentage); ?>%"></div>
								</div>
								
								<div class="content-info">
									<div class="booking-btn">
										<button class="book-btn" tabindex="0">
											<a href="<?php echo get_permalink($doctor_id); ?>">
												<?php esc_html_e('Book Appointment', 'doccure_elementor'); ?>
											</a>
										</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php endforeach; ?>
			</div>
			
			<?php if (!empty($settings['link'])): ?>
				<div class="slick-view-btn me-2">
					<a href="<?php echo esc_url($settings['link']); ?>" class="viewall">
						<?php esc_html_e('View More', 'doccure_elementor'); ?> <i class="fas fa-arrow-right ms-2"></i>
					</a>
				</div>
			<?php endif; ?>

		<?php } else if($settings['style']=='style3') { ?>
			<div class="best-doctor-slider">
				<?php 
				$counter = 0;
				foreach($my_query as $doctor):
					$counter++;
					$doctor_id = $doctor->ID;
					$has_subscription = $this->has_active_subscription($doctor_id);
					$subscription_package_name = $this->get_subscription_package_name($doctor_id);
					
					// Get doctor image
					if (has_post_thumbnail($doctor_id)) {
						$url = get_the_post_thumbnail_url($doctor_id, 'medium');
					} else {
						$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
					}
					
					// Get doctor data
					$feedback = get_post_meta($doctor_id, 'review_data', true);
					$feedback = !empty($feedback) ? $feedback : array();
					$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
					$total_percentage = !empty($feedback['dc_total_percentage']) ? $feedback['dc_total_percentage'] : 0;
					$name = doccure_full_name($doctor_id);
					$name = !empty($name) ? $name : '';
					$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
					$speciality = $this->get_doctor_speciality($doctor_id);
				?>
				<div>
					<div class="best-doctor-widget">
						<div class="best-doctor-image">
							<a href="<?php echo get_permalink($doctor_id); ?>">
								<img src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($name); ?>"/>
								<?php if ($show_subscription_badge && $has_subscription): ?>
									<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
										<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
									</div>
								<?php endif; ?>
							</a>
							<div class="overlay">
								<div class="pro-icon">
									<img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon2.png" alt="icon"/>
								</div>
							</div>
						</div>
						<div class="item-info">
							<div class="doctor-verify-overlay d-flex">
								<a href="javascript:void(0)" class="fav-icon" tabindex="0">
									<span class="doctor-writter"><?php esc_html_e('Verified', 'doccure_elementor'); ?></span>
									<?php do_action('doccure_get_doctorverification_check', $doctor_id, ''); ?>
								</a>
							</div>
						</div>
						<div class="provider-info text-center">
							<h3>
								<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
								<?php if ($has_subscription && !empty($subscription_package_name)): ?>
									<span class="subscription-indicator">
										<i class="fas fa-star"></i> <?php echo esc_html($subscription_package_name); ?>
									</span>
								<?php endif; ?>
							</h3>
							
							<?php if (!empty($speciality)): ?>
								<a href="#"><p><?php echo esc_html($speciality); ?></p></a>
							<?php endif; ?>
							
							<div class="ratings">
								<div class="empty-stars"></div>
								<div class="full-stars" style="width: <?php echo intval($total_percentage); ?>%"></div>
							</div>
							
							<div class="content-info">
								<div class="doctor-appointment-btn">
									<a class="btn btn-two" href="<?php echo get_permalink($doctor_id); ?>">
										<?php esc_html_e('Book Appointment', 'doccure_elementor'); ?>
									</a>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php endforeach; ?>
			</div>
			
			<?php if (!empty($settings['link'])): ?>
				<div class="text-center d-flex justify-content-center viewall_btn">
					<a href="<?php echo esc_url($settings['link']); ?>" class="viewall vc_btn3 vc_btn3-style-custom">
						<?php esc_html_e('View More', 'doccure_elementor'); ?>
					</a>
				</div>
			<?php endif; ?>

		<?php } else if($settings['style']=='style4') { ?>
			<div class="best-doctors-slider">
				<?php 
				$counter = 0;
				foreach($my_query as $doctor):
					$counter++;
					$doctor_id = $doctor->ID;
					$has_subscription = $this->has_active_subscription($doctor_id);
					$subscription_package_name = $this->get_subscription_package_name($doctor_id);
					
					// Get doctor image
					if (has_post_thumbnail($doctor_id)) {
						$url = get_the_post_thumbnail_url($doctor_id, 'medium');
					} else {
						$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
					}
					
					// Get doctor data
					$feedback = get_post_meta($doctor_id, 'review_data', true);
					$feedback = !empty($feedback) ? $feedback : array();
					$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
					$total_percentage = !empty($feedback['dc_total_percentage']) ? $feedback['dc_total_percentage'] : 0;
					$name = doccure_full_name($doctor_id);
					$name = !empty($name) ? $name : '';
					$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
					
					// Fallback for starting price
					if(empty($starting_price)) {
						$author_id = get_post_field('post_author', $doctor_id);
						if (!empty($author_id)) {
							$starting_price = get_user_meta($author_id, 'consultation_fee', true);
						}
					}
					
					$speciality = $this->get_doctor_speciality($doctor_id);
				?>
				<div>
					<div class="best-doctors-grid">
						<div class="best-doctors-img">
							<a href="<?php echo get_permalink($doctor_id); ?>">
								<img src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($name); ?>"/>
								<?php if ($show_subscription_badge && $has_subscription): ?>
									<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
										<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
									</div>
								<?php endif; ?>
							</a>
						</div>
						<div class="best-doctors-info">
							<h3>
								<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
								<?php if ($has_subscription && !empty($subscription_package_name)): ?>
									<span class="subscription-indicator">
										<i class="fas fa-star"></i> <?php echo esc_html($subscription_package_name); ?>
									</span>
								<?php endif; ?>
							</h3>
							
							<?php if (!empty($speciality)): ?>
								<a href="#"><p><?php echo esc_html($speciality); ?></p></a>
							<?php endif; ?>
							
							<?php if(!empty($starting_price)): ?>
								<h5 class="doctors-amount"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($starting_price); ?></h5>
							<?php else: ?>
								<h5 class="doctors-amount"><?php echo get_woocommerce_currency_symbol(); ?>0</h5>
							<?php endif; ?>
							
							<div class="ratings">
								<div class="empty-stars"></div>
								<div class="full-stars" style="width: <?php echo intval($total_percentage); ?>%"></div>
							</div>
							
							<div class="booking-btn">
								<a href="<?php echo get_permalink($doctor_id); ?>" class="btn" tabindex="0">
									<span>
										<?php esc_html_e('Book Appointment', 'doccure_elementor'); ?> <i class="fas fa-arrow-right ms-2"></i>
									</span>
								</a>
							</div>
						</div>
					</div>
				</div>
				<?php endforeach; ?>
			</div>

		<?php } else if($settings['style']=='style5') { ?>
			<section class="doctor-section">
				<div class="container">
					<div class="section-header sec-header-one text-center aos" data-aos="fade-up">
						<span class="badge badge-primary"><?php echo esc_html($settings['subtitle']); ?></span>
						<h2><?php echo esc_html($settings['title']); ?></h2>
					</div>
					<div class="doctors-slider owl-carousel aos" data-aos="fade-up">
						<?php 
						$counter = 0;
						foreach($my_query as $doctor):
							$counter++;
							$doctor_id = $doctor->ID;
							$has_subscription = $this->has_active_subscription($doctor_id);
							$subscription_package_name = $this->get_subscription_package_name($doctor_id);
							
							// Get doctor image
							if (has_post_thumbnail($doctor_id)) {
								$url = get_the_post_thumbnail_url($doctor_id, 'medium');
							} else {
								$url = get_template_directory_uri() . "/assets/images/dravatar-100x100.jpg";
							}
							
							// Get doctor data
							$feedback = get_post_meta($doctor_id, 'review_data', true);
							$feedback = !empty($feedback) ? $feedback : array();
							$total_rating = !empty($feedback['dc_total_rating']) ? $feedback['dc_total_rating'] : 0;
							$total_percentage = !empty($feedback['dc_total_percentage']) ? $feedback['dc_total_percentage'] : 0;
							$name = doccure_full_name($doctor_id);
							$name = !empty($name) ? $name : '';
							$starting_price = doccure_get_post_meta($doctor_id, 'am_starting_price');
							$dc_average_rating = !empty($feedback['dc_average_rating']) ? $feedback['dc_average_rating'] : 0;
							
							// Fallback for starting price
							if(empty($starting_price)) {
								$author_id = get_post_field('post_author', $doctor_id);
								if (!empty($author_id)) {
									$starting_price = get_user_meta($author_id, 'consultation_fee', true);
								}
							}
							
							$speciality = $this->get_doctor_speciality($doctor_id);
						?>
						<div class="card">
							<div class="card-img card-img-hover">
								<a href="<?php echo get_permalink($doctor_id); ?>">
									<img src="<?php echo esc_url($url); ?>" alt="<?php echo esc_attr($name); ?>">
									<?php if ($show_subscription_badge && $has_subscription): ?>
										<div class="subscription-badge" title="<?php echo esc_attr($subscription_package_name); ?>">
											<i class="fas fa-crown"></i> <?php esc_html_e('Premium', 'doccure_elementor'); ?>
										</div>
									<?php endif; ?>
								</a>
								<div class="grid-overlay-item d-flex align-items-center justify-content-between">
									<span class="badge bg-orange">
										<i class="fa-solid fa-star me-1"></i><?php echo esc_html($dc_average_rating); ?>
									</span>
								</div>
							</div>
							<div class="card-body p-0">
								<div class="d-flex active-bar align-items-center justify-content-between p-3">
									<?php if (!empty($speciality)): ?>
										<a href="#" class="text-indigo fw-medium fs-14"><?php echo esc_html($speciality); ?></a>
									<?php endif; ?>
									<?php if ($has_subscription && !empty($subscription_package_name)): ?>
										<span class="badge bg-warning-light d-inline-flex align-items-center">
											<i class="fas fa-crown fs-5 me-1"></i>
											<?php echo esc_html($subscription_package_name); ?>
										</span>
									<?php else: ?>
										<span class="badge bg-success-light d-inline-flex align-items-center">
											<i class="fa-solid fa-circle fs-5 me-1"></i>
											<?php esc_html_e('Available', 'doccure_elementor'); ?>
										</span>
									<?php endif; ?>
								</div>
								<div class="p-3 pt-0">
									<div class="doctor-info-detail mb-3 pb-3">
										<h3 class="mb-1 text-capitalize">
											<a href="<?php echo get_permalink($doctor_id); ?>"><?php echo esc_html($name); ?></a>
										</h3>
									</div>
									<div class="d-flex doctors_carousel_style5 align-items-center justify-content-between">
										<div>
											<p class="mb-1 consultation_fee"><?php esc_html_e('Consultation Fees', 'doccure_elementor'); ?></p>
											<?php if(!empty($starting_price)): ?>
												<h3 class="text-orange mb-0"><?php doccure_price_format($starting_price); ?></h3>
											<?php else: ?>
												<?php
												$doctor_user_id = get_post_field('post_author', $doctor_id);
												$am_starting_price = get_user_meta($doctor_user_id, 'consultation_fee', true);
												?>
												<h3 class="text-orange mb-0"><?php doccure_price_format($am_starting_price); ?></h3>
											<?php endif; ?>
										</div>
										<a href="<?php echo esc_url(site_url('/book-appointment/?doctor=' . intval($doctor_id))); ?>" class="btn btn-md btn-dark inline-flex align-items-center rounded-pill">
											<i class="isax isax-calendar-1 me-2"></i>
											<?php esc_html_e('Book Now', 'doccure_elementor'); ?>
										</a>
									</div>
								</div>
							</div>
						</div>
						<?php endforeach; ?>
					</div>
					<div class="doctor-nav home_new nav-bottom owl-nav"></div>
				</div>
			</section>
		<?php } ?>
		<?php 
	}
}