JLewis Posted September 1, 2022 Share Posted September 1, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315261-woocommerce-email-template/ Share on other sites More sharing options...
gizmola Posted September 1, 2022 Share Posted September 1, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315261-woocommerce-email-template/#findComment-1599976 Share on other sites More sharing options...
JLewis Posted September 5, 2022 Author Share Posted September 5, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315261-woocommerce-email-template/#findComment-1600112 Share on other sites More sharing options...
gizmola Posted September 5, 2022 Share Posted September 5, 2022 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). Quote Link to comment https://forums.phpfreaks.com/topic/315261-woocommerce-email-template/#findComment-1600121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.