WooCommerce购物车小计:显示“免费"而不是"0,00" [英] WooCommerce cart subtotal: Display 'free' instead of '0,00'

查看:51
本文介绍了WooCommerce购物车小计:显示“免费"而不是"0,00"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在WooCommerce购物车/结帐中显示免费"而不是€0.00的解决方案.

i am searching for a solution to display 'free' instead of €0,00 in the WooCommerce Cart/Checkout.

我知道,单一产品本身有一个代码段,但是即使在结帐/购物车页面的小计/小计中,也可以更改价格标签吗?

I know, there is a snippet for the Single Produkt itself, but is there a possibillity to change the price label even in the Subtotal/total calulation on the checkout/cart page?

add_filter( 'woocommerce_get_price_html', 'price_free_zero_empty', 9999, 2 );
   
function price_free_zero_empty( $price, $product ){
    if ( '' === $product->get_price() || 0 == $product->get_price() ) {
        $price = '<span class="woocommerce-Price-amount amount">FREE</span>';
    }  
    return $price;
}

推荐答案

尝试使用以下应显示免费"的内容.当产品价格等于零时:

Try to use the following that should display "Free" when the product price is equal to Zero:

// Cart and minicart
add_filter( 'woocommerce_cart_item_price', 'change_cart_item_price_html', 10, 3 );
function change_cart_item_price_html( $price_html, $cart_item, $cart_item_key ) {
    if( $cart_item['data']->get_price() == 0 ) {
        return '<span class="woocommerce-Price-amount amount">'.__("FREE", "woocommerce").'</span>';
    }
    return $price_html;
}

// Cart and Checkout
add_filter( 'woocommerce_cart_item_subtotal', 'change_checkout_item_subtotal_html', 10, 3 );
function change_checkout_item_subtotal_html( $subtotal_html, $cart_item, $cart_item_key ) {
    if( $cart_item['data']->get_price() == 0 ) {
        return '<span class="woocommerce-Price-amount amount">'.__("FREE", "woocommerce").'</span>';
    }
    return $subtotal_html;
}

代码进入您的活动子主题(或活动主题)的functions.php文件中.应该可以.

Code goes in functions.php file of your active child theme (or active theme). It should works.

这篇关于WooCommerce购物车小计:显示“免费"而不是"0,00"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆