如何将WhatsApp API链接添加至订单邮件并关联客户手机号?
Hey there! Let's walk through exactly how to add that dynamic WhatsApp link to your admin order completion notification emails—so you can shoot customers a quick confirmation message with one click. Here's what you need to do:
1. Locate the Customer Phone Variable in Your Email Template
First, you need to find the template variable that outputs your customer's phone number. This varies by platform/system:
- For WooCommerce, it's usually
{{customer.phone}}or{{billing_phone}} - For Shopify, look for
{{customer.phone}} - If you're using a custom system, it might be something like
{{user.mobile}}or{{order.customer.phone}}
Critical note: Make sure this variable outputs the full phone number with international country code (e.g., +1234567890, not just 1234567890). WhatsApp's API requires the country code to work correctly.
2. Build the Dynamic WhatsApp API Link
Embed the phone variable into WhatsApp's send URL, and pre-fill your confirmation message. Remember to URL-encode any spaces or special characters in your text (otherwise the link might break):
Example HTML Link (for template systems that support HTML):
<a href="https://api.whatsapp.com/send?phone={{customer.phone}}&text=Hi%21%20We%27ve%20successfully%20received%20your%20order.%20We%27ll%20process%20it%20and%20update%20you%20shortly.%20Thanks%20for%20shopping%20with%20us%21">Message Customer via WhatsApp</a>
Example Markdown Link (if your template uses Markdown):
[Message Customer via WhatsApp](https://api.whatsapp.com/send?phone={{customer.phone}}&text=Hi%21%20We%27ve%20successfully%20received%20your%20order.%20We%27ll%20process%20it%20and%20update%20you%20shortly.%20Thanks%20for%20shopping%20with%20us%21)
Quick Tip for Text Encoding:
If you don't want to manually encode your message, use encodeURIComponent("Your message here") in your browser's developer console to generate the URL-safe version automatically.
3. Insert the Link into Your Email Template
Head to your system's email template editor (usually under "Settings > Emails" or "Template Management") and paste the link code in a logical spot—like below the order details, or next to other customer contact options.
4. Handle Edge Cases (Optional but Recommended)
If some customers don't provide a phone number, add a conditional check to hide the link when there's no number available. Here's how that might look in a few common systems:
WooCommerce (using PHP in template):
<?php if ( ! empty( $order->get_billing_phone() ) ) : ?> <a href="https://api.whatsapp.com/send?phone=<?php echo esc_attr( $order->get_billing_phone() ); ?>&text=Hi%21%20We%27ve%20successfully%20received%20your%20order...">Message Customer via WhatsApp</a> <?php endif; ?>
Shopify (using Liquid):
{% if customer.phone != blank %} <a href="https://api.whatsapp.com/send?phone={{ customer.phone }}&text=Hi%21%20We%27ve%20successfully%20received%20your%20order...">Message Customer via WhatsApp</a> {% endif %}
5. Test It Out!
Send a test order notification to yourself, click the link, and verify that:
- WhatsApp opens to the correct customer number
- Your pre-filled message shows up exactly as you wrote it
That's all—you're ready to streamline your post-order communication with one-click WhatsApp messages!
内容的提问来源于stack exchange,提问作者Yatir

