Modify php function. If Empty display this number.

Hi, I sm trying to write a function in WordPress, which works with WP Job Manager.

The function is a phone number field. The below code is working,  but i want to edit it so that if i don't enter a number, it will display a default number, ie what's in the placeholder.

How would i modify the code below to do this?

/* ------ Add Phone Number ------- */
add_filter( 'job_manager_job_listing_data_fields', 'admin_add_phonenumber_field' );
function admin_add_phonenumber_field( $fields ) {
  $fields['_job_phonenumber'] = array(
    'label'       => __( 'Recruiting PhoneNumber', 'job_manager' ),
    'type'        => 'text',
    'placeholder' => '800-998-2221',
    'description' => ''
  );
  return $fields;
}

/* ------ Add Phone Number ------- */
add_action( 'single_job_listing_meta_end', 'display_job_phonenumber_data' );
function display_job_phonenumber_data() {
  global $post;

  $phonenumber = get_post_meta( $post->ID, '_job_phonenumber', true );

  if ( $phonenumber ) {
    echo 'Call Now To Speak With A Recruiter <a href="tel:' . esc_html( $phonenumber ) . '">' . esc_html( $phonenumber ) . '</a>';
  }
}

Open in new window

Jon ImmsWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You mean something like this

$phonenumber = get_post_meta( $post->ID, '_job_phonenumber', true );
$phonenumber = empty($phonenumber) ? '800-998-2221' : $phonenumber

Open in new window

In other words if phone number is empty then default it to default otherwise use it as is

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.