# Candidate Pricing Feature

This feature adds hourly and daily pricing functionality for candidates in the Jobster plugin.

## Features

- **Price per Hour**: Compulsory field for hourly rate
- **Price per Day**: Compulsory field for daily rate
- **Hours per Day**: Specifies how many hours are included in the daily rate
- **Pricing Calculator**: Interactive calculator to estimate costs
- **Shortcode Support**: Easy display of pricing on any page

## Admin Usage

### Adding Pricing to Candidates

1. Go to **Candidates** in the WordPress admin
2. Edit any candidate or create a new one
3. In the **Candidate Details** section, you'll find:
   - **Price per Hour** (required)
   - **Price per Day** (required)
   - **Hours per Day** (required, default: 8)

### Validation

- All pricing fields are required
- Values must be positive numbers
- Hours per day must be between 1 and 24
- Form validation prevents saving with invalid values

## Frontend Usage

### Shortcode

Use the `[candidate_pricing]` shortcode to display candidate pricing:

```
[candidate_pricing]
```

#### Shortcode Parameters

- `candidate_id`: ID of the candidate (default: current post ID)
- `show_calculator`: Show/hide the pricing calculator (default: 'true')
- `currency`: Currency symbol (default: '$')

#### Examples

```
[candidate_pricing]
[candidate_pricing candidate_id="123"]
[candidate_pricing show_calculator="false" currency="€"]
```

### PHP Functions

You can also use these PHP functions in your theme:

```php
// Get hourly rate
$hourly_rate = jobster_get_candidate_hourly_rate($candidate_id);

// Get daily rate
$daily_rate = jobster_get_candidate_daily_rate($candidate_id);

// Get hours per day
$hours_per_day = jobster_get_candidate_hours_per_day($candidate_id);

// Get formatted pricing display
$pricing_html = jobster_get_candidate_pricing_display($candidate_id, '$');

// Calculate rate for specific hours
$rate_info = jobster_calculate_candidate_rate($candidate_id, 40, '$');
```

## Pricing Calculator

The pricing calculator allows users to:
- Enter the number of hours they need
- Get an instant cost estimate
- See whether the calculation is based on hourly or daily rates

### How It Works

1. **Hourly Rate Priority**: If hourly rate is set, calculations use hourly rate
2. **Daily Rate Fallback**: If no hourly rate, calculations use daily rate
3. **Daily Rate Calculation**: For daily rates, it calculates the number of days needed based on hours per day

## Styling

The feature includes CSS classes for easy customization:

- `.candidate-pricing-container`: Main container
- `.candidate-pricing-header`: Header section
- `.candidate-pricing-item`: Individual pricing items
- `.candidate-pricing-calculator`: Calculator section
- `.candidate-pricing-result`: Calculator results

## JavaScript API

For custom implementations, you can use the global JavaScript function:

```javascript
jobsterCalculateCandidateRate(candidateId, hours, function(response) {
    if (response.success) {
        console.log('Estimated cost:', response.data.formatted);
    }
});
```

## AJAX Endpoints

- `jobster_calculate_candidate_rate`: Calculate pricing for specific hours
- Requires nonce verification
- Returns JSON response with pricing details

## Database Fields

The following meta fields are added to candidates:

- `candidate_hourly_rate`: Hourly rate (decimal)
- `candidate_daily_rate`: Daily rate (decimal)
- `candidate_hours_per_day`: Hours per day (integer)

## Requirements

- WordPress 5.0+
- PHP 7.4+
- jQuery (included with WordPress)

## Support

For support or feature requests, please contact the plugin developer. 