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

在WooCommerce PDF发票中显示优惠券折扣后的商品小计

解决发票显示优惠券抵扣后商品成本的问题

Hey there! Let's figure out why swapping $totals for $discount isn't working to show the post-coupon item cost on your invoice. Here are some practical fixes to try:

  • First, confirm your $discount variable is calculated correctly
    It’s possible the variable isn’t actually holding the discounted amount you expect. Double-check where you define it—make sure it’s properly subtracting the coupon value from the base price. For example:

    // Adjust these variables to match your code's structure
    $base_item_cost = 99.99; // Original pre-coupon price
    $coupon_amount = 15.00; // Amount the coupon covers
    $discount = $base_item_cost - $coupon_amount; // Should equal 84.99 here
    

    Also, make sure this variable is being passed into the context where your invoice template renders. If it’s not sent to the template at all, referencing $discount won’t display anything meaningful.

  • Check for typos or scope issues in your template
    Sometimes the problem is as simple as a misspelled variable name (like $discounts instead of $discount) or the variable not being accessible in your template’s scope. Add a quick debug line to your invoice template to see what the variable actually contains:

    <!-- Temporarily add this to your invoice template -->
    <?php var_dump($discount); ?>
    

    If it outputs NULL or the original base price, you know the variable isn’t being set correctly upstream.

  • Look for code that overwrites the $discount variable
    Scan through the code that runs right before rendering the invoice. Is there any line that resets $discount back to the base price? For example, a function that recalculates order totals without accounting for the coupon could be overwriting your value.

  • Ensure coupon logic is applied to item-level costs
    If your coupon only affects the overall order total but not individual item costs, $discount might not reflect the per-item discounted price you need for the invoice. You may need to adjust your coupon logic to calculate and store the discounted cost for each item separately.

Once you’ve sorted out these checks, updating your invoice template to use the correctly populated $discount variable should display the post-coupon item cost as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:42:01