• PHP Help
  • Proper syntax for tracking link in .php file.

I am trying to make the tracking code a link in a WooCommerce email template. The code I'm using is:

<?php
/* translators: %s Order date */
    printf(
        esc_html__('Tracking number : <a href=\\"https://www.fedex.com/fedextrack/?trknbr=%2$s\\">%2$s</a>"','woocommerce'),
        esc_html($shipping_carrier),
        esc_html($ups_trackingno)
    );
?>

The problem is the email generated by this code looks like this:

Hi Tyler,
Your order has shipped.

Tracking number : <a href=\"https://www.fedex.com/fedextrack/?trknbr=277530011950\">277530011950</a>"

It shows the entire link rather than the tracking code as a link. Any help would be appreciated.

    Added [code]...[/code] tags around your code block. Please be sure to use in future posts to aid readability here. 🙂

      I don't think you want to escape that text, plus the quoting seems wrong. No guarantees, but I'd try:

          printf(
              'Tracking number: <a href="https://www.fedex.com/fedextrack/?trknbr=%2$s">%2$s</a>'),
              esc_html($shipping_carrier),
              esc_html($ups_trackingno)
          );
      

      (Escaping the link text would convert things like < to &lt;, causing it to not be treated as an HTML tag by the browser.)

        Write a Reply...