1. Home
  2. Developer
  3. Code Snippets
  4. Display modified Apply button text if a previous application for the same job is detected

Display modified Apply button text if a previous application for the same job is detected

Sometimes candidates apply for the same job multiple times, creating unwanted duplicate applications. One way to reduce these duplicated applications is to inform candidates when they have already applied for a job.

Here’s a possible way to do that by saving a cookie to the browser with the job’s id, then checking for that cookie in php templates.

The code below sets a cookie on application submission, then checks for the presence of that cookie in a template file, using filters to modify the button text if the cookie is present.

// <your-child-theme>/functions.php (or whichever file you're using for matador customizations)

// Set a cookie on application submission
add_action( 'matador_new_job_application', 'matador_add_applied_cookie', 10, 2 );
function matador_add_applied_cookie( $wp_id, $application ) {

    $job_id = $application['jobs'][0]['bhid'];

    if ( empty( $job_id ) ) {
        return;
    }

    $cookie_name = 'matador_job_applied_' . $job_id;

    if ( isset( $_COOKIE[ $cookie_name ] ) ) {
        return;
    }

    setcookie( $cookie_name, $job_id, strtotime( '+365 days' ), COOKIEPATH, COOKIE_DOMAIN );
}

// Modify the application button text on the jobs archive page
function matador_modify_apply_btn( $buttons, $rule, $context ) {
    $updated_buttons = $buttons;
    $updated_buttons['application'] = 'Applied';

    return $updated_buttons;
}

And here is the code detecing the cookie and changing the button text accordingly:

// <your-child-theme>/matador/parts/jobs-listing-job.php

/* template code */

$applied_cookie_is_set = isset( $_COOKIE['matador_job_applied_' . matador_get_the_job_bullhorn_id() ] );

?>

<footer 
            class="matador-job-footer <?php echo $applied_cookie_is_set ? "matador-applied" : ""; ?>"
        >

            <?php if ( isset( $fields['link'] ) && $fields['link'] ) : ?>
                <?php 
                    
                    if ( $applied_cookie_is_set ) {  
                        add_filter( 'matador_template_the_job_navigation_buttons', 'matador_modify_apply_btn', 99, 3 );
                    }
                    
                    matador_the_job_navigation( get_the_ID(), 'append' );
                    
                    if ( $applied_cookie_is_set ) {
                        remove_filter( 'matador_template_the_job_navigation_buttons', 'matador_modify_apply_btn', 99, 3 ); 
                    }
                ?>
            <?php endif; ?>

  / * template code continues */
Updated on October 31, 2024
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support