How can we show the before price on the order email?
-
Hi there everyone,
Hope you are doing well.
How can we show the before and after prices on the orders? Like currently the order emails just show the final price, but we also want to show the before price showing customers the amounts they got off.
Thanks for any help you can provide!
-
Hi @gregthegreg5,
Thanks for reaching out.
If I understand you correctly, you’re looking to show the before and after prices in order emails. Is that correct?
In this case, you’ll need to customize your email templates. However, this will need custom coding, which is out of our support scope.
With that said, I suggest reaching out to a developer, as this involves custom coding and implementations. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:
- WooCommerce Developer Resources Portal
- WooCommerce Advanced Facebook group
- WooCommerce Developer Slack Channel
- Hire a?WooCommerce Expert
Hope this helps!
Step 1: Override the Email Template
To customize the order email template, you’ll need to copy the relevant template file to your theme or child theme:Locate the Email Template:
Go to wp-content/plugins/woocommerce/templates/emails/.
Find the file email-order-items.php. This template controls how order items are displayed in the email.
Copy the Template:Copy the email-order-items.php file to your child theme’s WooCommerce folder:
wp-content/themes/your-child-theme/woocommerce/emails/.
Step 2: Modify the Template to Display Both Prices
Open the copied email-order-items.php file in your child theme and modify it as follows:Find the Code that Outputs the Item Price:
Look for a line similar to this:<?php echo $item->get_total(); ?>
Add Code to Display the Original Price and Sale Price:
<?php
$product = $item->get_product();
$regular_price = $product->get_regular_price(); // Original price
$sale_price = $product->get_sale_price(); // Sale price
$final_price = $item->get_total() / $item->get_quantity(); // Final price after discount
if ($regular_price && $regular_price > $final_price) {
echo '<del>' . wc_price($regular_price) . '</del> '; // Strikethrough original price
echo '<ins>' . wc_price($final_price) . '</ins>'; // Final sale price
} else {
echo wc_price($final_price); // If no discount, show the final price only
}
?>The code checks if the product has a sale price and if the original (regular) price is higher than the final price.
If it does, it displays the original price with a strikethrough () and the sale price in a different style ().
If there’s no discount, it simply shows the final price.
Please let me know if you need further help
Thanks
Ahir HemantHello @ckadenge Thanks we will look it over!
Yes, we are looking to do that. Is there any forum on www.remarpro.com where we can ask or where people provide paid help? We are trying to find people who offer customization services etc. I do see a list you provided so we will go over that.
Hello @hemant-ahir
Thank you so much for the code, we will try this out! Thanks for taking the time and providing this.
Really appreciate your time and help guys ??
Hi @gregthegreg5,
Is there any forum on www.remarpro.com where we can ask or where people provide paid help? We are trying to find people who offer customization services etc.
You can try the following group for assistance:
Hope this helps.
Hello @hemant-ahir
We could not find that line (sorry if we missed it), but this is what we saw on there;
<?php
/**- Order details table shown in emails.
* - This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/email-order-details.php.
* - HOWEVER, on occasion WooCommerce will need to update template files and you
- (the theme developer) will need to copy the new files to your theme to
- maintain compatibility. We try to do this as little as possible, but it does
- happen. When this occurs the version of the template file will be bumped and
- the readme will list any important changes.
* - @see https://woocommerce.com/document/template-structure/
- @package WooCommerce\Templates\Emails
- @version 3.7.0
*/
defined( ‘ABSPATH’ ) || exit;
do_action( ‘woocommerce_email_before_order_table’, $order, $sent_to_admin, $plain_text, $email );
/* translators: %1$s: Order ID. %2$s: Order date */
echo wp_kses_post( wc_strtoupper( sprintf( esc_html__( ‘Order #%1$s‘, ‘woocommerce’ ), $order->get_order_number(), wc_format_datetime( $order->get_date_created() ) ) ) ) . “\n”;
echo “\n” . wc_get_email_order_items( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$order,
array(
‘show_sku’ => $sent_to_admin,
‘show_image’ => false,
‘image_size’ => array( 32, 32 ),
‘plain_text’ => true,
‘sent_to_admin’ => $sent_to_admin,
)
);echo “==========\n\n”;
$item_totals = $order->get_order_item_totals();
if ( $item_totals ) {
foreach ( $item_totals as $total ) {
echo wp_kses_post( $total[‘label’] . “\t ” . $total[‘value’] ) . “\n”;
}
}if ( $order->get_customer_note() ) {
echo esc_html__( ‘Note:’, ‘woocommerce’ ) . “\t ” . wp_kses( wptexturize( $order->get_customer_note() ), array() ) . “\n”;
}if ( $sent_to_admin ) {
/* translators: %s: Order link. */
echo “\n” . sprintf( esc_html__( ‘View order: %s’, ‘woocommerce’ ), esc_url( $order->get_edit_order_url() ) ) . “\n”;
}do_action( ‘woocommerce_email_after_order_table’, $order, $sent_to_admin, $plain_text, $email );
Also, is it possible to add this code on something like Code Snippets versus the mail files on cPanel?
Thanks ??
Hi ,
Also, is it possible to add this code on something like Code Snippets versus the mail files on cPanel?
In most cases, it is recommended to add custom code to your child theme or use third-party plugins like code-snippets.
As for adding code to your CPanel, it is not recommended to add any code there, however, you can reach out to your host and consult on that.
Also, I would recommend creating a staging site and testing out the code before adding it to your live store.
All the best.
- The topic ‘How can we show the before price on the order email?’ is closed to new replies.