Last active
November 13, 2023 15:05
-
-
Save braddalton/f7137bfc35895f5f66cc35148452e450 to your computer and use it in GitHub Desktop.
Add Product Expiration Date To Order Emails Full Tutorial https://wpsites.net/product/woocommerce/add-expiration-date-to-order-emails/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_email_order_details', 'add_custom_fields_to_order_email', 10, 4); | |
function add_custom_fields_to_order_email($order, $sent_to_admin, $plain_text, $email) { | |
foreach ($order->get_items() as $item_id => $item) { | |
$product_id = $item->get_product_id(); | |
$expiration_date = get_post_meta($product_id, '_expiration_date', true); | |
if ( ! empty( $expiration_date ) ) { | |
$expiration_date = get_post_meta($product_id, '_expiration_date', true); | |
$date_of_purchase = $order->get_date_created()->date('Y-m-d'); / | |
$product_name = $item->get_name(); | |
echo '<p><strong>Product Name:</strong> ' . esc_html($product_name) . '</p>'; | |
echo '<p><strong>Date of Purchase:</strong> ' . esc_html($date_of_purchase) . '</p>'; | |
echo '<p><strong>Expiration Date:</strong> ' . esc_html($expiration_date) . '</p>'; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment