Woocommerce小数 [英] Woocommerce decimal quantity

查看:86
本文介绍了Woocommerce小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我找到一种在woocommerce中使用十进制值(例如3.56)作为数量的方法吗?

can you help me to find a way for use decimal value like 3.56 for quantity in woocommerce ?

在计算价格数量时转换为整数值,但是我需要价格用用户输入的值计算

in calculate price quantity number convert to Integers value but i need price calculate with Values that the user has inputed

我正在使用woocommerce 2.2.8

i am working with woocommerce 2.2.8

推荐答案

您必须为WooCommerce的某些挂钩添加一些功能。

You have to add some functions, for some of the hooks i WooCommerce.

// Add min value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_min', 'min_decimal');
function min_decimal($val) {
    return 0.1;
}

// Add step value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
function nsk_allow_decimal($val) {
    return 0.1;
}

// Removes the WooCommerce filter, that is validating the quantity to be an int
remove_filter('woocommerce_stock_amount', 'intval');

// Add a filter, that validates the quantity to be a float
add_filter('woocommerce_stock_amount', 'floatval');

我已经为此功能编写了一个教程,其中有一些额外的修复程序,解释如下: http://codeontrack.com/use-decimal-in-quantity-fields -in-woocommerce-wordpress /

I have written a tutorial, for this functionality, with some extra fixes an explanation at: http://codeontrack.com/use-decimal-in-quantity-fields-in-woocommerce-wordpress/

这篇关于Woocommerce小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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