Hi,
to make price and location required add the code below in your theme functions.php file
add_filter( "adverts_form_load", "customize_adverts_add_11405396" );
function customize_adverts_add_11405396( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( in_array($field["name"], array( "adverts_price", "adverts_location" ) ) ) {
$form["field"][$key]["is_required"] = true;
$form["field"][$key]["validator"] = array( array( "name" => "is_required" ) );
}
}
return $form;
}
Hi Greg,
thanks for your answer.
I use this code in function.php.
Location required working perfect.
Problem is with the price. Near the Price includes the symbol * but if I do not fill price and click on the preview, I am not be warned that this field is mandatory.
Please how to fix it?
Thanks
You will need one additional code snippet, the price field is actually never empty as even without a value it will have the value automatically set to 0.
add_filter( "adverts_form_load", "adverts_form_load_11115" );
function adverts_form_load_11115( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( $field["name"] != "adverts_price" ) {
continue;
}
adverts_form_add_filter("no_leading_zero", array(
"callback" => "no_leading_zero"
));
$form["field"][$key]["filter"][] = array( "name" => "no_leading_zero" );
$form["field"][$key]["validator"] = array( array( "name" => "is_required" ) );
}
return $form;
}
function no_leading_zero( $data ) {
return ltrim( $data, "0" );
}
Perfect, working!
Thank you 🙂