【问题标题】:Change number of decimals on Woocommerce displayed cart subtotal更改 Woocommerce 显示的购物车小计的小数位数
【发布时间】:2019-08-20 18:46:13
【问题描述】:

我正在使用 "Change number of decimals in Woocommerce cart totals" 答案代码以 2 位小数 显示总数。该代码适用于购物车和结帐页面中显示的总数。

如果可能的话,我也想对小计做同样的事情。任何帮助表示赞赏。

【问题讨论】:

    标签: php wordpress woocommerce decimal cart


    【解决方案1】:

    要在购物车和结帐页面中使用 2 位小数格式化显示的小计金额,请使用以下命令:

    // Displayed formatted cart subtotal in cart and checkout pages
    add_filter( 'woocommerce_cart_subtotal', 'filter_cart_subtotal_html', 10, 3 );
    function filter_cart_subtotal_html( $cart_subtotal, $compound, $cart ) {
        $decimals = 2; // <==  <==  Set the number of decimals to be displayed
    
        $args = ['decimals' => strval($decimals)]; // Initializing
    
        if ( $compound ) {
            $cart_subtotal = wc_price( $cart->get_cart_contents_total() + $cart->get_shipping_total() + $cart->get_taxes_total( false, false ), $args );
    
        } elseif ( $cart->display_prices_including_tax() ) {
            $cart_subtotal = wc_price( $cart->get_subtotal() + $cart->get_subtotal_tax(), $args );
    
            if ( $cart->get_subtotal_tax() > 0 && ! wc_prices_include_tax() ) {
                $cart_subtotal .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
            }
        } else {
            $cart_subtotal = wc_price( $cart->get_subtotal(), $args );
    
            if ( $cart->get_subtotal_tax() > 0 && wc_prices_include_tax() ) {
                $cart_subtotal .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
            }
        }
    
        return $cart_subtotal;
    }
    

    代码位于活动子主题(或活动主题)的functions.php 文件或插件文件中。经过测试并且可以工作。

    相关:Change number of decimals in Woocommerce cart totals

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-21
      相关资源
      最近更新 更多