I have a Text type custom attribute named listing_primary_number.
I’m trying to populate the value for this attribute from the vendor’s primary_number attribute when submiting a new listing
I can successfully fetch the primary number but cannot set the custom attribute value whatever I try, it’s always empty.
This is my code:
add_filter(
'hivepress/v1/forms/listing_update',
function( $form ) {
if ( current_user_can('edit_posts') ) {
$vendor = HivePress\Models\Vendor::query()->filter(['user' => get_current_user_id(),])->get_first();
if ( $vendor ) {
$primary_number = $vendor->get_primary_number();
if (isset($form['fields']['listing_primary_number'])) {
$form['fields']['listing_primary_number']['default'] = $primary_number;
} else {
error_log('The field does not exist');
}
}
}
return $form;
},
1000
);
If i set the description to $primary_number, I see it in the description so I know it’s working.
But it doesn’t populate the text input