You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce自定义邮件开发需求:同时展示常规价与折扣价

Hey Pim, let's fix that manual calculation hassle and get your order notification email showing both the regular order details and the discounted supplier price automatically. Here are a few practical solutions tailored to different scenarios:

解决方案建议

1. Use Built-in Features of Your E-commerce Platform

If you're using a mainstream platform like WooCommerce or Shopify, you can add the discounted price directly to your email templates without heavy coding:

For WooCommerce:

  • Add a custom calculation to your order email template. You can either edit the template file directly (via your theme's woocommerce/emails folder) or use a snippet plugin like Code Snippets to inject the logic:
    // Place this in your functions.php or a code snippet plugin
    add_action( 'woocommerce_email_after_order_table', 'add_discounted_supplier_price' );
    function add_discounted_supplier_price( $order ) {
        $regular_total = $order->get_total();
        $discounted_total = $regular_total * 0.8;
        echo '<h3>Supplier Purchase Details</h3>';
        echo '<p>Regular Order Total: ' . wc_price( $regular_total ) . '</p>';
        echo '<p>*20% Discounted Supplier Price*: ' . wc_price( $discounted_total ) . '</p>';
    }
    
  • This will automatically append the discounted price section to every order email sent to your inbox.

For Shopify:

  • Edit your order notification email template (Settings > Notifications > Order Confirmation > Edit code) and insert this Liquid code wherever you want the discounted price to appear:
    <h3>Supplier Purchase Details</h3>
    <p>Regular Order Total: {{ order.total_price | money }}</p>
    <p>*20% Discounted Supplier Price*: {{ order.total_price | times: 0.8 | money }}</p>
    
  • Save the template, and every new order email will calculate and display the discounted price automatically.

2. Custom Code for Self-Built Websites

If your site is custom-developed, integrate the discount calculation directly into your order processing workflow:

  1. When an order is created, fetch the regular order total from your database.
  2. Calculate the discounted price with a simple formula: discounted_price = regular_total * 0.8
  3. Pass both values to your email template, so the final email includes sections like:

Customer Order Details
Total Paid by Customer: $XXX.XX

Supplier Purchase Request
20% Discount Applied: $YYY.YY

Example backend snippet (Python, for reference):

# Assuming regular_total is pulled from your order data
regular_total = 150.00
discounted_total = regular_total * 0.8

# Pass these values to your email renderer
email_context = {
    "regular_total": regular_total,
    "discounted_total": discounted_total
}

3. No-Code Automation Tools

If you don't want to touch code, use automation tools to handle the calculation and email delivery:

  • Tools like Zapier or Make (Integromat) can trigger off new orders from your website.
  • Add a "Calculate" step to compute 80% of the order total.
  • Set up an action to send an email to your inbox with both the regular order details and the pre-calculated discounted price.
  • This is a great option if you're not comfortable with coding or need a quick setup.

Quick Tips to Avoid Errors

  • If taxes or shipping are excluded from the supplier discount, adjust the calculation to target only the product subtotal instead of the full order total.
  • Add a clear label like 20% Supplier Discount next to the discounted price to avoid confusion with customer-facing pricing.

内容的提问来源于stack exchange,提问作者Pim Hoek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:43:57