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

WooCommerce 3.3.x替换产品0价格为自定义文本的技术方案问询

Solution for Replacing €0,00 Price with "Based on contract" in WooCommerce 3.3.x

Got it, let's get this sorted for your WooCommerce 3.3.x store. Since recent WooCommerce updates changed how price rendering works, older code snippets often break. Here's a reliable fix that works both on your store's frontend and in order confirmation emails:

Step 1: Add the Custom Code

Paste this code into your theme's functions.php file (or use a custom code plugin like Code Snippets to avoid losing changes when updating your theme):

// Replace €0,00 price with 'Based on contract' on store frontend
add_filter('woocommerce_get_price_html', 'replace_zero_price_with_contract_text', 10, 2);
function replace_zero_price_with_contract_text($price, $product) {
    // Only apply on frontend (skip admin dashboard)
    if ($product->get_price() == 0 && !is_admin()) {
        return __('Based on contract', 'woocommerce');
    }
    return $price;
}

// Replace €0,00 price in order confirmation emails
add_filter('woocommerce_order_item_price', 'replace_zero_price_in_emails', 10, 3);
function replace_zero_price_in_emails($price_html, $item, $args) {
    $product = $item->get_product();
    // Check if the product exists and has a 0 price
    if ($product && $product->get_price() == 0) {
        return __('Based on contract', 'woocommerce');
    }
    return $price_html;
}

How It Works

  • Frontend Replacement: The woocommerce_get_price_html hook controls how prices are displayed on product pages, shop archives, and cart pages. We check if the product's price is 0 and we're not in the admin area, then swap the €0,00 text with your custom message.
  • Email Replacement: The woocommerce_order_item_price hook targets the price displayed in order emails. We fetch the product from the order item, verify its price is 0, and replace the price text there too.

Quick Notes

  • To change the text, just replace 'Based on contract' with whatever phrase you need. Keeping it wrapped in __() ensures it works with WooCommerce's multi-language features if you use them later.
  • Test thoroughly: Check a 0-price product on your frontend, place a test order, and confirm the custom text shows up in the order email.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:10:53