How to Add Dynamic WhatsApp Button in Your Website for Products and Services Using ACF

Table of Contents

Imagine a consumer visiting your website, seeing a product they adore, and then sending you a quick WhatsApp message with pre-filled product and service details. No need to write the details manually about the product or services, and avoid wasting time. This is the potential of a dynamic WhatsApp button using WordPress’s Advanced Custom Fields (ACF) and PHP code.

Make sure you have:

  1. ACF: The WordPress plugin for custom fields.
  2. Page Builder: Elementor (free or Pro) or any other page builder that supports ACF.
  3. A phone number: WhatsApp Business Account.
  4. Editor for Code: Use a plugin such as WPCode to insert PHP code.

Set Up ACF Fields

First, we need custom fields to store product or service details. These fields will feed into the WhatsApp message.

Install ACF:

Go to Plugins > Add New in WordPress.

Install and activate the ACF plugin.

install and activate acf plugin

Create a Field Group:

Navigate to Post Types > Add New.

add new post types

Name the post type (e.g., “Car Lists”).

create post types

Add New Field Groups:

I named the field “Car Details”

Create these fields:

whatsapp_link (Type: Text or URL, Label: WhatsApp Link)

Stores the dynamic WhatsApp URL.

car_year (Type: Text or Number, Label: Car Year)

For the product’s year (e.g., 2020).

deposit (Type: Text or Number, Label: Deposit)

For the deposit amount (e.g., CAD 1000).

car_image (Type: Image, Label: Car Image, Return Format: Image Array)

For the product’s image URL.

Create any other field you want to display in your dynamic content.

Add new field with car details

Select display location to “Car Lists” for this field group.

Save the field group.

Select display location for the fiend group

Add all of your dynamic content details one-by-one.

Never touch the “WhatsApp Link” field. We’ll do custom PHP code for that. If you write anything in this field, you’ll not get the result.

add-dynamic-content-details

Create your dynamic content and include the PHP code for dynamic WhatsApp Message and links.

Now design the dynamic content and trigger this with ACF fields. Example output of the design –

Let’s add the PHP code after the dynamic content has been designed.  The main feature is a PHP filter that uses the values in the ACF field to create the WhatsApp connection.  We’ll dynamically change the output of the WhatsApp_link field using the acf/format_value filter. We’ll use WPCode for safer modifications (we’ll add the PHP code for this article using the WPCode plugin).

Go to Plugins > Add New Plugin.

Install and activate WPCode plugin.

install wpcode plugin

Add the Code:

Now hover on Code Snippets > Add new snippet

add new snippet

Hover on “Add Your Custom Code (New Snippet)” > Add Custom Snippet

add custom snippet

Select PHP Snippet

Select PHP Snippet

Paste this code and edit this according to your ACF field name.

add_filter('acf/format_value/name=whatsapp_link', 'generate_whatsapp_link_with_details', 10, 3);
function generate_whatsapp_link_with_details($value, $post_id, $field) {
    // Get the car name from the post title
    $car_name = get_the_title($post_id);

    // Get the car year from ACF field (replace 'car_year' if your field name differs)
    $car_year = get_field('car_year', $post_id) ?: 'N/A';
	
    // Get the deposit from ACF field (replace 'deposit' if your field name differs)
    $deposit = get_field('deposit', $post_id) ?: 'N/A';

    // Get the car image URL from ACF field (replace 'car_image' if your field name differs)
    $car_image = get_field('car_image', $post_id);
    if (is_array($car_image) && isset($car_image['url'])) {
        $car_image_url = $car_image['url']; // If ACF returns an array
    } else {
        $car_image_url = $car_image ?: ''; // If ACF returns a URL directly
    }

    // Construct the message
    $message = "I'm interested in this car: \n Name: {$car_name} \n Year: {$car_year} \n Deposit: CAD {$deposit}";
    if ($car_image_url) {
        $message .= "\n Image: {$car_image_url}";
    }

    // Encode the message for URL safety
    $encoded_message = urlencode($message);

    // Build the WhatsApp link
    $value = "https://wa.me/1016642***?text=" . $encoded_message;

    return $value;
}

Replace the following value from the code:

Replace all the ‘car_year’ with your field name.

Replace all the ‘deposit’ with your field name

Replace all the ‘car_image’ with your field name

You can also customize this message as well: “I’m interested in this car: \n Name: {$car_name} \n Year: {$car_year} \n Deposit: CAD {$deposit}”;

Replace CAD with your currency.

Replace “1016642***” this number with your WhatsApp Business number.

Important: Never touch the whatsapp_link value and keep the same name in your field name as well.

Now activate and update the code.

activate and update code snippet

The final output of the button will something look like the below screenshot.

confirm dynamic whatsapp button in acf

An ACF dynamic WhatsApp message button is revolutionary for consumer engagement.  With this method, my clients’ inquiry rates have skyrocketed.  Use this tutorial to modify the code and improve the interactivity of any WordPress website.

Transform Your Customer Experience

A dynamic WhatsApp button with ACF is a game-changer for connecting with customers. From car dealerships to bakeries, my clients have seen inquiry rates soar with this solution. Follow this guide, customize the code, and elevate your WordPress site’s interactivity.

Have a unique use case? Share it in the comments! Explore our blogs for more tips, or contact us for a free consultation.

Implemented this button? Tell us how it worked or share your tweaks below. Subscribe to our newsletter for WordPress hacks, or get started with your dynamic WhatsApp button with ACF today!

Some Frequently Asked Questions

What is a Dynamic WhatsApp Button in WordPress, and Why Does It Matter in 2025?

A dynamic WhatsApp button in WordPress allows users to instantly message a business on WhatsApp with pre-filled, tailored content, such as a product’s name, price, or image URL, using data from custom fields. Unlike static links, it creates a personalized experience, improving customer engagement. In 2025, with WhatsApp’s 2.78 billion users (as noted in the article), this feature is crucial for businesses like e-commerce stores or service providers. The article highlights a 30% increase in inquiry rates for a car dealership after implementing this button, showing its impact on conversions and user interaction.

How Can Advanced Custom Fields (ACF) Be Used to Create a Dynamic WhatsApp Button in WordPress?

Advanced Custom Fields (ACF) allows you to create custom fields in WordPress to store product or service data, which can then be used to generate dynamic WhatsApp links. As outlined in the article, you start by installing ACF, creating a field group (e.g., “Car Details”), and adding fields like whatsapp_link (Text/URL), car_year (Text/Number), deposit (Text/Number), and car_image (Image). Then, use PHP code with the acf/format_value filter in your theme’s functions.php to dynamically populate the whatsapp_link field with a URL like https://wa.me/[phone]?text=[message], pulling in field values such as the product name, year, and deposit. This method ensures flexibility and avoids plugin bloat.

What Are the Benefits of Using ACF for a Dynamic WhatsApp Button Over Other Plugins?

Using ACF for a dynamic WhatsApp button offers several advantages, as noted in the article:
Flexibility: Customize messages with any field (e.g., product name, price).
Scalability: Works for one product or thousands using WordPress’s post system.
No Plugin Bloat: Unlike plugins like Contact Form 7, ACF is lightweight and avoids adding unnecessary load (e.g., the article mentions Contact Form 7 added 300ms to page load).
Developer Control: Fine-tune output with PHP for precise functionality.
Compared to alternatives like Contact Form 7 or custom plugins, ACF provides a leaner, more customizable solution, ideal for developers seeking efficiency and control.

What Are the Prerequisites for Building a Dynamic WhatsApp Button with ACF in WordPress?

To build a dynamic WhatsApp button with ACF in WordPress, you’ll need:
A WordPress site (version 6.5 or higher recommended, per the article).
The ACF plugin installed and activated.
A page builder like Elementor (free or Pro) for easy integration, though other builders work too.
Basic PHP knowledge (optional) to edit your theme’s functions.php file safely.
A WhatsApp Business account with a phone number in international format (e.g., +1 (XXX) XXX-XXXX).
Access to a code editor via FTP or a plugin like WPCode for adding custom PHP snippets.
These ensure you can set up and test the button effectively.

How Do I Set Up ACF Fields for a Dynamic WhatsApp Button in WordPress?

To set up ACF fields for a dynamic WhatsApp button, follow these steps from the article:
Install and activate the ACF plugin from Plugins > Add New in WordPress.
Navigate to Post Types > Add New, create a post type (e.g., “Car Lists”), and name your field group (e.g., “Car Details”).
Add fields: whatsapp_link (Text/URL), car_year (Text/Number), deposit (Text/Number), and car_image (Image, return format: Image Array).
Set the display location to your post type (e.g., “Car Lists”) and save the field group.
Avoid manually entering data in the whatsapp_link field, as it will be populated dynamically via PHP.
This setup allows you to pull dynamic data into WhatsApp messages seamlessly.

Affordable web development of Rifat

Mirajur Rahman Rifat

Website Developer
Contact Me
Contact Me

Let’s Build Your Dream Website

Your website is your brand’s digital heartbeat. A platform to showcase your value and convert visitors into customers. With my expertise, proven track record, and passion for excellence, I’ll craft a website that not only meets your needs but surpasses your expectations. Let’s collaborate to create a digital solution that drives results and sets you apart from the competition.

Ready to transform your online presence? Contact me today for a free consultation and let’s start building your future!

Leave a Reply

Your email address will not be published. Required fields are marked *

Request a Quote

Let’s Create Something Amazing Together