Create Vendor programatically

I’m trying to create a Vendor before going to Complete Profile page.
I’m trying to create this class:

// Add vendor.
$vendor = ( new Models\Vendor() )->fill(
		'name'        => $user->get_display_name(),
		'description' => $user->get_description(),
		'slug'        => $user->get_username(),
		'status'      => 'auto-draft',
		'image'       => $user->get_image__id(),
		'user'        => $user->get_id(),

But with no success. I’m trying to use this on my functions.php
Can you help me please?



The code itself is correct, but it depends on how it’s used, e.g. is there a $user object in the function context, and which hook is used to execute this code?

Also, $vendor->save() call is required after this, and if it returns false then you can check the validation errors in $vendor->_get_errors().

I highly recommend using the default vendor registration flow, by default the vendor object is created right after the first submission of the Complete Profile form.

Hi ihor,
It was just a little problem, on my functions.php, it doesn’t know the object “new Models\Vendor()”, it needed to be “new Hivepress\Models\Vendor()”. Now is ok.
Yes thanks for recomendations.
I’m saving the object after creation.
I’m skipping the Complete Profile form, so users doesn’t need to repeat the same process over and over again.

1 Like

Thanks for sharing this. I was looking for a way to do this, too, since the vendor attribute fields don’t show up on the “Complete Profile” form. It’s kind of silly to just fill out some of the questions, then go to the settings and have to fill out more. Just fill it all out at once.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.