【问题标题】:Add thousand separator to product quantity in WooCommerce在 WooCommerce 中为产品数量添加千位分隔符
【发布时间】:2020-09-12 02:50:31
【问题描述】:

我们公司订购了 1000 件产品销售的门户交易。

我正在尝试在数量上添加一千个分隔符以使其更易于阅读(而不是打字)。它应该看起来像价格的千位分隔符。 我一直在尝试在我的子主题功能页面中添加一些自定义代码:

// define the woocommerce_quantity callback
function filter_woocommerce_quantity( $quantity, $product ) {

// filter
return number_format($stock_quantity,0,”.”,”,”);
};

// add the filter
add_filter( ‘woocommerce_quantity’, ‘filter_woocommerce_quantity’, 10, 2 );

到目前为止,还没有运气。有什么明显的我做错了,还是这是一个更复杂的问题?

【问题讨论】:

    标签: php wordpress woocommerce number-formatting hook-woocommerce


    【解决方案1】:

    要格式化一个数以千计的数字,您可以使用

    参数

    • number - 正在格式化的数字。
    • decimals - 设置小数位数。
    • dec_point - 设置小数点的分隔符。
    • thousands_sep - 设置千位分隔符。

    使用以下代码,将在结帐页面调整数量显示

    function filter_woocommerce_checkout_cart_item_quantity( $item_qty, $cart_item, $cart_item_key ) {
        // Get quantity
        $cart_item_quantity = $cart_item['quantity'];
        
        // Format
        $cart_item_quantity = number_format($cart_item_quantity, 0, ',', ' ');
        
        // Output
        $item_qty = '<strong class="product-quantity">' . sprintf( '&times;&nbsp;%s', $cart_item_quantity ) . '</strong>';
    
        // Return
        return $item_qty;
    }
    add_filter( 'woocommerce_checkout_cart_item_quantity', 'filter_woocommerce_checkout_cart_item_quantity', 10, 3 );
    

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 2021-04-19
      • 2018-10-25
      • 2015-07-12
      • 2013-09-02
      • 2012-07-12
      相关资源
      最近更新 更多