Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add custom fields to my woocommerce completed email WordPress

  • SOLVED

Hello,

I am looking to modify my woocommerce completed email to show an order custom field. I already have the code just want to modify the tracking link to include the tracking number. The final output will be : "<p><a href="https://track.brightledshoes.com/TrackingNumber">Click This Link To Track Your Package</a></p>"

The custom fields are _aftership_tracking_number and _aftership_tracking_provider

add_action( 'woocommerce_email_before_order_table', 'wc_email_before_order_table', 20 );
function wc_email_before_order_table( $order ) {
$provider = get_post_meta( $order->get_id(),'_aftership_tracking_provider',true);
$number = get_post_meta( $order->get_id(),'_aftership_tracking_number',true);
echo sprintf( __( '<p>Tracking Provider: %s</p>', 'woocommerce' ), $provider );
echo sprintf( __( '<p>Tracking Number: %s</p>', 'woocommerce' ), $number );
echo '<p><a href="track.brightledshoes.com">Click This Link To Track Your Package</a></p>';
}

Answers (5)

2018-06-26

Reigel Gallarde answers:

Hello George,

Please try this:

add_action( 'woocommerce_email_before_order_table', 'wc_email_before_order_table', 20 );
function wc_email_before_order_table( $order ) {
$provider = get_post_meta( $order->get_id(),'_aftership_tracking_provider',true);
$number = get_post_meta( $order->get_id(),'_aftership_tracking_number',true);
echo sprintf( __( '<p>Tracking Provider: %s</p>', 'woocommerce' ), $provider );
echo sprintf( __( '<p>Tracking Number: %s</p>', 'woocommerce' ), $number );
echo sprintf( __( '<p><a href="track.brightledshoes.com/%s">Click This Link To Track Your Package</a></p>', 'woocommerce' ), $number );
}


George Sprouse comments:

works great Reigel! :)

2018-06-26

Rempty answers:

add_action( 'woocommerce_email_before_order_table', 'wc_email_before_order_table', 20 );
function wc_email_before_order_table( $order ) {
$provider = get_post_meta( $order->get_id(),'_aftership_tracking_provider',true);
$number = get_post_meta( $order->get_id(),'_aftership_tracking_number',true);
echo sprintf( __( '<p>Tracking Provider: %s</p>', 'woocommerce' ), $provider );
echo sprintf( __( '<p>Tracking Number: %s</p>', 'woocommerce' ), $number );
echo '<p><a href="https://track.brightledshoes.com/'.$number .'">Click This Link To Track Your Package</a></p>';
}

2018-06-26

Darlene Grace Arcenal answers:

Hi,

Try this code:

add_action( 'woocommerce_email_before_order_table', 'wc_email_before_order_table', 20 );
function wc_email_before_order_table( $order ) {
$provider = get_post_meta( $order->get_id(),'_aftership_tracking_provider',true);
$number = get_post_meta( $order->get_id(),'_aftership_tracking_number',true);
echo sprintf( __( '<p>Tracking Provider: %s</p>', 'woocommerce' ), $provider );
echo sprintf( __( '<p>Tracking Number: %s</p>', 'woocommerce' ), $number );
echo '<p><a href="https://track.brightledshoes.com/'.$number.'">Click This Link To Track Your Package</a></p>';
}

2018-06-26

Cesar Contreras answers:

Hi, Please try this:

add_action( 'woocommerce_email_before_order_table', 'wc_email_before_order_table', 20 );
function wc_email_before_order_table( $order ) {
$provider = get_post_meta( $order->get_id(),'_aftership_tracking_provider',true);
$number = get_post_meta( $order->get_id(),'_aftership_tracking_number',true);
echo sprintf( __( '<p>Tracking Provider: %s</p>', 'woocommerce' ), $provider );
echo sprintf( __( '<p>Tracking Number: %s</p>', 'woocommerce' ), $number );
echo sprintf( __( '<p><a href="track.brightledshoes.com/%s">Click This Link To Track Your Package</a></p>', 'woocommerce' ), $number );

echo'<p><a href="track.brightledshoes.com/' . $number . ' ">Click This Link To Track Your Package</a></p>'

2018-06-26

Arnav Joy answers:

Is these meta is added in orders meta ??
And you just need code to display them ?