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 need help outputting a custom field from an order that is used for the tracking number. I would like to use email hooks to output this field. I have been looking at this guide https://businessbloomer.com/woocommerce-visual-hook-guide-emails/

The custom fields are _aftership_tracking_number and _aftership_tracking_provider

I attached a screenshot of where I want the ouput to locate in the email

Answers (3)

2018-06-03

Arnav Joy answers:

You can use following

<?php echo get_post_meta( $order_id,'_aftership_tracking_number',true); ?>

2018-06-03

Reigel Gallarde answers:

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


Reigel Gallarde comments:

you need to put this in your current active theme's functions.php
Let me know if there's a problem.


George Sprouse comments:

Hi Reigel

Great that worked! Do you know how I can add text before displaying the field like in the example below

Your item has been shipped! Here are your tracking details

Shipped with (_aftership_tracking_provider)
Tracking Number: _aftership_tracking_number

<a href="track.brightledshoes.com">Click This Link To Track Your Package</a>

Thanks!


Reigel Gallarde comments:

add this as the third echo...

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


Reigel Gallarde comments:

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>';
}


Reigel Gallarde comments:

Ahh missed the "Your item has been shipped! Here are your tracking details" part...

use 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 '<p>Your item has been shipped! Here are your tracking details</p>';
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>';
}


Reigel Gallarde comments:

Hello, any problem with the last code? let me know.

Please don't forget to accept the answer.

Cheers!
Reigel
http://reigelgallarde.me

2018-06-04

User179955 answers:

i think the below plugin should help you dude..
https://wordpress.org/plugins/aftership-woocommerce-tracking/


User179955 comments:

you may also try this-https://www.aftership.com/apps/woocommerce


User179955 comments:

https://help.aftership.com/hc/en-us/articles/115008489548
https://github.com/avishai/aftership-apps-woocommerce

with all details of the help ful plugins..


User179955 comments:

have a look at this too..
https://codecanyon.net/item/shipping-details-pro-plugin-for-woocommerce/8158288?ref=consil