you have two returns there. that’s not right. I think you mean to use “echo” for the first one.
Hi,
Thanks for your response. I tried it, it doesn’t work anyway
I am trying to get this displayed with these three options. In all cases no result
1:<?php _e( do_shortcode( ‘[tracking_code]’ ) ); ?>
2:[tracking_code]
3:<?php echo $shipping_tracking_code; ?>
I’d write it as
function tracking_shortcode( ) {
$order = new WC_Order( $order_id );
$shipping_tracking_code = get_post_meta( $order->id, '_shipping_tracking_code', true );
return "Your shipping code is: " . $shipping_tracking_code;
}
add_shortcode( 'tracking_code', 'tracking_shortcode' );
Does whatever you’re using to send the email handle shortcodes?
I tried this.
Now it returns only
‘Your shipping code is:,
The value of $shipping_tracking_code is not returned.
Btw i m trying to get this in woocommerce email
The value of $shipping_tracking_code is not returned.
So that indicates that there’s something wrong with your call to get_post_meta. That’s where you need to focus your attention or on the previous call, which may not be returning anything useful in $order.
Email content does not get echoed, it is compiled into a variable and included in wp_mail() parameters. Any solution that uses a variant of echo will fail. What you need to do is add your content to that variable that contains the other mail content. I’m pretty sure Woocommerce provides a filter for this, but I’m not certain about what it’s called.
It can be found by digging through WC code, which can be a frustrating, though informative process. If you ask at the dedicated WC support forum someone should be able to tell you.
BTW, I know you were simply fishing for a solution, but your use of the _e() translation function is so wrong in so many ways it makes me cringe π I mention this not to be critical, but for the sake of anyone else reading who doesn’t know better.
<?php
/**
* Add Promo code text to the Order emails
*/
add_action( 'woocommerce_email_before_order_table', 'add_tracking_code', 20);
function add_tracking_code( $order, $is_admin_email ) {
$shipping_tracking_code = get_post_meta( $order->id, '_shipping_tracking_code', true );
$url = 'http://www.rapido.bg/information/tracking-tovaritelnitsa';
$order = new WC_Order( $order_id );
if($order->status === 'shipped' ) {
ob_start();
?>
<h3 style="text-align: center;"><?php _e( 'Your order tracking no', 'my-plugin' ); ?></h3>
<div>
<p style="text-align: justify;"><?php _e( 'Your order has been shipped from our warehouse thru courier service Rapido. Waybill no is: ', 'my-plugin' ); ?><font size="3" color="red"><b><?php echo $shipping_tracking_code; ?></b></font></p>
<p><a href="<?php echo $url; ?>" ><?php _e( 'Track your shipment', 'my-plugin' ); ?></a></p>
</div>
<?php
echo ob_get_clean();
} else {
echo ' ';
}
}
?>
Above is the snippet which works well in customer note email
Can’t understand why it doesn’t work here, I mean cannot get the valipue of $shipping_tracking_code
@bcworkz
Hi, thanks, will do the home work.
Sorry, I am just a beginner with no practical knowledge of coding.