在Woocommerce中仅清除一些结帐字段值 [英] Clear only some checkout fields values in Woocommerce

查看:72
本文介绍了在Woocommerce中仅清除一些结帐字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Woocommerce中,我试图清除结帐字段。因此,当用户以前订购某商品,现在又订购某物时,他/她将不得不再次写出他/她的所有信息。



我正在使用这段代码

  function clear_checkout_fields($ input){
return'';
}

add_filter('woocommerce_checkout_get_value','clear_checkout_fields',1);

现在此代码清除了所有字段,但同时也更改了我的增值税,显示为0。 / p>

有人知道这个解决方案吗?

解决方案

有些 woocommerce_checkout_get_value 挂钩函数中的参数错误。

实际上有2个参数:




  • $ value 自变量,因为它是过滤器挂钩而返回,

  • $ imput 参数,可用于定位任何结帐字段。



因此,在您的情况下,将使用 $ imput 参数,以避免清空您的自定义增值税结帐字段。在下面的代码中,您需要将 vat_number 替换为在自定义增值税中设置的正确的字段 name 属性结帐字段:

  add_filter('woocommerce_checkout_get_value','clear_checkout_fields',10,2); 
函数clear_checkout_fields($ value,$ input){
if($ input!='vat_number')
$ value =‘;;

返回$ value;
}

代码进入活动子主题(或活动主题)的function.php文件)。经过测试,可以正常工作。


In Woocommerce i am trying to clear the checkout fields. so when a user that has ordered something before, and is now ordering something again, he/she will have to write in all his/her information again.

i am using this code

function clear_checkout_fields($input){
return '';
}

add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' , 1);

Now this code is clearing all the fields, but it also changes my VAT to show as 0.

does anyone know a solution to this?

解决方案

There is some arguments errors in your woocommerce_checkout_get_value hooked function.
There is in fact 2 arguments:

  • the $value argument that is returned as it is a filter hook,
  • the $imput argument that you can use to target any checkout field.

So in your case you will use the $imput argument, to avoid your custom VAT checkout field to be emptied. In the code bellow, you will need to replace vat_number by the correct field name attribute that is set in your custom VAT checkout field:

add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' , 10, 2 );
function clear_checkout_fields( $value, $input ){
    if( $input != 'vat_number' )
        $value = '';

    return $value;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于在Woocommerce中仅清除一些结帐字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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