【问题标题】:WooCommerce cart subtotal: Display 'free' instead of '0,00'WooCommerce 购物车小计:显示“免费”而不是“0,00”
【发布时间】:2020-09-21 15:39:44
【问题描述】:

我正在寻找在 WooCommerce 购物车/结帐中显示“免费”而不是 €0,00 的解决方案。

我知道,Single Produkt 本身有一个 sn-p,但是即使在结帐/购物车页面上的小计/总计计算中也有可能更改价格标签吗?

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;
}

【问题讨论】:

    标签: php wordpress woocommerce cart hook-woocommerce


    【解决方案1】:

    尝试使用当产品价格为零时应显示“免费”的以下内容:

    // 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 文件中。它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      相关资源
      最近更新 更多