【问题标题】:Manage independently the decimal number of the price of each product [duplicate]独立管理每个产品价格的十进制数[重复]
【发布时间】:2019-06-30 12:13:51
【问题描述】:

我使用 woocommerce 开发了一个在线商店,我想在价格包含 3 时以 3 位小数显示产品的价格(示例 1)。但是当价格的最后一个数字是 0 时,我只想显示 2 位小数(示例 2)。请问你知道怎么做吗?

我找到了一个过滤器,但它同时影响所有价格:

add_filter( 'wc_get_price_decimals' , 'custom_price_decimals', 20, 1 );
function custom_price_decimals( $decimals ) {
  if( is_product() || is_shop() || is_product_category() || is_product_tag() || is_cart() || is_checkout() ){
    $decimals = 3;
    return $decimals;
  }
}

感谢您的帮助:)

示例 1

示例 2

【问题讨论】:

  • 请使用 Stack Overflow 图像托管程序而不是 noelshack。

标签: php woocommerce decimal price


【解决方案1】:

你可以这样做:

$decimals=strlen(ltrim(($float - floor($float)),"0."));

返回点后不带零的数字

【讨论】:

    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 2020-05-17
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多