【问题标题】:Clear checkout fields for specific user(s) in WooCommerce清除 WooCommerce 中特定用户的结帐字段
【发布时间】:2021-03-14 13:45:53
【问题描述】:

此代码为所有人清除结帐页面的所有输入。我想清除特定用户的所有输入。我该怎么做。

 add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' );
function clear_checkout_fields($input)
    {
        return '';
    }

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce userid


    【解决方案1】:

    对于已定义的用户ID,您可以使用(在IF语句中设置相关的用户ID)

    add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
    function clear_checkout_fields( $input ) {
        if ( get_current_user_id() == 259 ) {
            return '';
        }
        return $input;
    }
    

    或者对于一组用户ID:

    add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
    function clear_checkout_fields( $input ) {
        if ( in_array( get_current_user_id(), array( 259, 321, 336 ) ) {
            return '';
        }
        return $input;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-26
      • 2017-03-27
      • 2018-11-20
      • 1970-01-01
      • 2019-03-14
      • 2019-10-15
      • 2022-01-03
      • 2017-06-19
      相关资源
      最近更新 更多