Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 预填充电子商务签出字段_Php_Wordpress_Woocommerce_Checkout_Hook Woocommerce - Fatal编程技术网

Php 预填充电子商务签出字段

Php 预填充电子商务签出字段,php,wordpress,woocommerce,checkout,hook-woocommerce,Php,Wordpress,Woocommerce,Checkout,Hook Woocommerce,我正试图在woocommerce结帐页面中预填充其他字段,但我正在努力 add_filter('woocommerce_checkout_get_value', function($input, $key ) { global $current_user; switch ($key) : case 'billing_first_name': case 'shipping_first_name': return $curre

我正试图在woocommerce结帐页面中预填充其他字段,但我正在努力

add_filter('woocommerce_checkout_get_value', function($input, $key ) {
    global $current_user;

    switch ($key) :
        case 'billing_first_name':
        case 'shipping_first_name':
            return $current_user->first_name;
        break;
        case 'billing_last_name':
        case 'shipping_last_name':
            return $current_user->last_name;

        case 'billing_phone':
            return $current_user->phone;
        break;
                case 'billing_company':
                case 'shipping_company':
            return $current_user->company;
        break;
                case 'billing_vat':
            return $current_user->vat;
        break;
    endswitch;
}, 10, 2);
除了$current\u user->phone、$current\u user->company、$current\u user->vat之外,它可以正常工作


有什么帮助吗?

电话、公司和其他信息都在元数据中

 $phone = get_user_meta($current_user,'phone_number',true);
您也不需要有全局变量。这也是危险的

 add_filter('woocommerce_checkout_get_value', function($input, $key ) 
    {
     $current_user = get_current_user_id();

    switch ($key) :
    case 'billing_first_name':
    case 'shipping_first_name':
        return $current_user->first_name;
    break;
    case 'billing_last_name':
    case 'shipping_last_name':
        return $current_user->last_name;

    case 'billing_phone':
        $phone = get_user_meta($current_user,'phone_number',true);
        return  $phone;
    break;

    case 'billing_company':
    case 'shipping_company':
         // May or may not be in meta data
    break;

   case 'billing_vat':
       // Not available through user
    break;
   endswitch;
   }, 10, 2);
您可以在此处看到更多信息:

增值税有点复杂,因为它基于国家而不是用户名。当国家在那里时,增值税将不会被取消。最好的方法是通过商业来获取

至于公司名称,有时称为组织,也不是直接的Wordpress。它通常是通过第三方插件添加的,如woocommerce、memberships或将该功能添加到帐户的自定义插件。你必须看看你在用什么。

就这样用吧

全局$当前用户

“计费电话”案例: 返回$current\u user->billing\u phone;
中断

请添加一些解释,以便其他人能够理解!如果可能的话,添加您尝试过的代码。您好,您不想使用$phone=get\u user\u meta$current\u user,'phone\u number',true;退回$phone;相反,只要用我的上面,这是工作的罚款。