在WooCommerce中将千位分隔符添加到产品数量中 [英] Add thousand separator to product quantity in WooCommerce

查看:111
本文介绍了在WooCommerce中将千位分隔符添加到产品数量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的公司订购了1000笔产品销售中的门户交易.

Our company orders portal deals in 1000’s of product sales.

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

I am trying to add a thousand separator to the quantity to make it easier to read (not as typing). It should appear like the thousand separator of price. I’ve been trying to add in some custom code to my child theme functions page:

// 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 );


到目前为止,还不是运气.是否有明显的地方我做错了,还是这是一个更复杂的问题?


So far, not luck. Is there anything obvious that i’m doing wrong, or is this a more complex problem?

推荐答案

要对成千上万的数字进行格式化,可以使用

To format a number with grouped thousands you could use

  • number_format — Format a number with grouped thousands

参数

  • 数字-要格式化的数字.
  • 小数-设置小数点的数量.
  • dec_point-设置小数点的分隔符.
  • thousands_sep-设置千位分隔符.

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

With the following code, the quantity display will be adjusted on the checkout page

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

这篇关于在WooCommerce中将千位分隔符添加到产品数量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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