【问题标题】:Return the value of user meta key and change the value to number返回用户元键的值并将值更改为数字
【发布时间】:2019-11-25 11:59:08
【问题描述】:
add_filter( 'gform_field_value_bank3_code', 'my_custom_population_showbank' );
function my_custom_population_showbank( $value ) {
$current_user = wp_get_current_user();
$users = $current_user->userpinn;
return $users;

}

但我想如果用户元键的值是 Canada 它应该将 Canada 更改为像 340 这样的数字 但如果值为 America,则应返回 500

这个概念是我想按他们的国家/地区提取我网站中用户的用户元密钥。所以 $current_user->userpinn; out 将当前用户国家放在他的元密钥上。使用 userpinn 作为国家元键。

  • 现在我想如果当前用户来自英格兰,它应该返回 400

  • 如果当前用户来自英国,则应返回 580

  • 如果当前用户来自加拿大,则应返回 320

这就是我想为每个不同的国家/地区执行此操作的方式,而不是返回英格兰,它应该返回 400 的数字,我希望该函数在单个文本字段或数字字段上,而不是在下拉列表中。

【问题讨论】:

  • 使用 switch case 你可以归档你的功能
  • 国家/地区存储在哪个元值中?
  • 请尝试以下代码,如果您有任何疑问或疑问,请随时询问。

标签: wordpress gravity-forms-plugin


【解决方案1】:
$country_name = 'your user meta value here';
switch ($country_name) {
    case "England":
        $return_country_code = 400;
        break;
    case "United Kingdom":
        $return_country_code = 580;
        break;
    case "Canada":
        $return_country_code = 320;
        break;
    default:
        $return_country_code = 400; //Default code if you want.

    return $return_country_code;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多