Hey guys, I have added 2 fields in vendor attribute: “pan_number” & “id_card”. Both these fields are visible in the profile settings of the vendor. Now I tried writing a code as given below, that whenever a vendor requests payout, the code must check whether the vendor has updated both pan number & ID card fields. If yes, then the payout will be processed, if not it will display error message & ask the vendor to update the same.
add_filter(
'hivepress/v1/forms/payout_request/errors',
function( $errors, $form ) {
if ( is_user_logged_in() && hivepress()->vendors->is_vendor() ) {
$vendor = hivepress()->vendors->get_vendor();
$pan_number = $vendor->get_attribute( 'pan_number' );
$id_card = $vendor->get_attribute( 'id_card' );
if ( empty( $pan_number ) || empty( $id_card ) ) {
$errors[] = 'Please update your valid PAN number and ID card.';
}
}
return $errors;
},
1000,
2
);
I have added the above code in the functions.php of the child theme.
The vendor makes a payout request, clicks submit & vendor gets message “Your payout request has been submitted.”
Vendor checks in the payout tab, but No payout is processed.
So what am I doing wrong? Can you help me fix this?
Please let me know if you created a custom “vendors” components because the code you posted must cause a PHP error because there are no functions like is_vendor(), get_vendor() and hivepress()->vendors component.
It’s possible to get the vendor profile by user ID and fetch attributes, but this requires custom coding. Please consider making these attributes required, then new vendors will not be able to register unless they fill these values.
Thanks for your response! Custom vendor components were creating issues. So I changed the code to following & it works for now, please correct me if I have done any mistake.
add_filter(
'hivepress/v1/forms/payout_request/errors',
function( $errors, $form ) {
$user_id = get_current_user_id();
// Check if the user is logged in and has a valid ID.
if ( $user_id && class_exists( 'HivePress\Models\Vendor' ) ) {
// Get the vendor profile by user ID.
$vendor = HivePress\Models\Vendor::query()->filter( [ 'user' => $user_id ] )->get_first();
// Check if the vendor profile is valid.
if ( $vendor ) {
// Retrieve pan_number and id_card attributes.
$pan_number = $vendor->get_attribute( 'pan_number' );
$id_proof = $vendor->get_attribute( 'id_proof' );
// Check if either pan_number or id_card is empty.
if ( empty( $pan_number ) || empty( $id_proof ) ) {
$errors[] = 'Please update your valid PAN number and ID card.';
}
}
}
return $errors;
},
1000,
2
);