On WooCommerce I have a custom field days_manufacture
for each product with different (integer) values.
Also I Have this code that displays a message on cart page with the highest value of "days of manufacture":
add_action('woocommerce_before_cart', 'days_of_manufacture');
function days_of_manufacture() {
$day_txt = ' ' . __('day', 'your_theme_domain_slug' );
$days_txt = ' ' . __('days', 'your_theme_domain_slug' );
$text = __('Your Order will be produced in: ', 'your_theme_domain_slug' );
$max_days = 0;
foreach( WC()->cart->get_cart() as $cart_item )
if($cart_item['days_manufacture'] > $max_days)
$max_days = $cart_item['days_manufacture'];
if($max_days != 0) {
if ($max_days == 1)
$days_txt = $day_txt;
$output = $text . $max_days . $days_txt;
echo "<div class='woocommerce-info'>$output</div>";
}
}
Now I would like to display this message in thankyou
view order page and in My account > Orders > View order
pages.
Is it possible?
Thanks!
Yes it is… but as there is no available hooks for this on the corresponding templates, You will have to override 2 templates (for that please read how to override woocommerce templates via a theme).
Step 1 - The function
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Step 2 - inserting the function in the templates
1) The My Account view order template:
This template is located in
your_theme/woocommerce/myaccount/view-order.php
Here is an extract of this template (with the function inside it):
2) The Thankyou view order template:
This template is located in
your_theme/woocommerce/checkout/thankyou.php
Here is an extract of this template (with the function inside it):
This code is tested and working
References: