Is there any way that I can add some Product custom field I create to include in WooCommerce Completed Order email.
I have created come custom fields as below :
And I have added some code to my theme's functions.php file, to display those custom fields values as follow:
add_action( 'woocommerce_email_after_order_table', 'add_content_on_specific_email', 20, 4 );
function add_content_on_specific_email( $order, $sent_to_admin, $plain_text, $email )
{
if ( $email->id == 'customer_completed_order' ) {
echo '<h3>Informasi Pengambilan Barang</h3><p class="email-upsell-p">Terima Kasih telah mengkonfirmasi pembayaran Anda, Silahkan tunjukan email ini pada saat pengambilan barang dan berikut informasi dan alamat pengambilan barang:</p>';
echo '<ul><li>Alamat Pengambilan:</strong> ' . get_post_meta( $product_id, 'kontak_pemberi', true) . '</li>
<li>No. Telepon :</strong> ' . get_post_meta( $product_id, 'no_hp_pemberi', true) . '</li>
<li>Nama Pemberi Barang :</strong> ' . get_post_meta( $product_id, 'nama_pemberi', true) . '</li>
</ul>';
}
}
But I never get those custom fields values. What am I doing wrong?
get_post_meta( $product_id..
where is$product_id
defined? also know that there are a lot of related or even duplicate questions out there. So first use the search function before asking your question – 7uc1f3r