Untitled

 avatar
user_6710311
plain_text
10 months ago
1.2 kB
1
Indexable
<?php

namespace App\Models\Wordpress;

use Corcel\Model\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class WPUser extends User
{
    use HasFactory;
    protected $hidden = ['meta'];
    protected $appends = ['address1', 'address2', 'phone', 'companyName'];

    public function getAddress1Attribute()
    {
        foreach ($this->meta as $value) {
            if ($value->meta_key == 'billing_address_1') {
                return $value->meta_value;
            }
        }
        return '';
    }

    public function getAddress2Attribute()
    {
        foreach ($this->meta as $value) {
            if ($value->meta_key == 'billing_address_2') {
                return $value->meta_value;
            }
        }
        return '';
    }

    public function getPhoneAttribute()
    {
        foreach ($this->meta as $value) {
            if ($value->meta_key == 'billing_phone') {
                return $value->meta_value;
            }
        }
        return '';
    }

    function getCompanyNameAttribute() {
        foreach ($this->meta as $value) {
            if ($value->meta_key == 'nickname_7') {
                return $value->meta_value;
            }
        }
        return '';
    }
}
Editor is loading...
Leave a Comment