Jump to content

Recommended Posts

I’m trying to get the tracking link added to a WooCommerce email and I think I have incorrect syntax. Would appreciate some help. Here is the section in question:

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


It's outputting this on the email message:
Tracking number : echo " <a href=\"https://www.fedex.com/fedextrack/?trknbr=277442046164\">277442046164</a>";

I want it to output this on the email (with the number being the link):

Tracking number: 277442046164

Link to comment
https://forums.phpfreaks.com/topic/315261-woocommerce-email-template/
Share on other sites

Please use the <> for adding code snippets in the future.  I edited your original post.

Remove the echo.  You are already calling multiple functions, which take parameters.  Parameters can not include php blocks or statements.

As it is, the printf function is returning output.  If you look at the php manual for printf you should be able to see why it is being used here.  It takes parameters and injects them into the string using the parameters being passed to it.  

<?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)
    );
?>

 

I reformatted the block so you can more easily see the functions and parameters being passed.

 

Hi gizmola,

Thanks for the response. I changed the code in the .php file with your modifications. Unfortunately, this is what the email looks like with those edits:

----------------------------------------------------------------------

Hi Tyler,

Your order has shipped.

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

-----------------------------------------------------------------------

 I attached the complete document as a TXT file.

email-netsuite-trackingno-received.txt

Having looked at the code further, you don't want to use the esc_html___ function, or at least not on the url.  That function is changing the anchor tag markup so that it no longer will function as a url.   Try this instead:

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

I don't know if your site is multilingual, but the primary purpose of esc_html__() is to do translation, but it also "escapes" any html as I mentioned.  Obviously there is no reason to translate the url, but you might need translation of the text string "Tracking number" (or not).  

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.