When I add this part to the offer form, it does not work as I want, and here I want the calculation process to occur and be shown in the $total_field field.
add_filter(
'hivepress/v1/forms/offer_make',
function ($form) {
// Define the field properties for السعر
$price_field = [
'label' => 'السعر',
'type' => 'number',
'min_length' => 5,
'max_length' => 100,
'required' => true, // Set the field as required
'_order' => 10,
];
// Define the field properties for الضريبة
$vat_field = [
'label' => 'الضريبة',
'type' => 'number',
'default' => '15%', // Set the default value to "15%"
'placeholder' => '15%', // Set the placeholder text to "15%"
'min_length' => 5,
'max_length' => 100,
'disabled' => true, // Set the field to disabled
'required' => true, // Set the field as required
'_order' => 20, // Display after السعر
];
// // Define the field properties for رسوم متر
$meter_fee_field = [
'label' => 'رسوم متر',
'type' => 'number',
'default' => '35', // Set the default value to "35"
'placeholder' => '35', // Set the placeholder text to "35"
'min_length' => 5,
'max_length' => 100,
'disabled' => true, // Set the field to disabled
'required' => true, // Set the field as required
'_order' => 30, // Display after الضريبة
];
// // Define the field properties for المجموع
$total_field = [
'label' => 'المجموع',
'type' => 'number',
'min_length' => 5,
'max_length' => 100,
'disabled' => true, // Set the field to disabled
'required' => true, // Set the field as required
'_order' => 40, // Display after رسوم متر
];
// // Define the field properties for تفاصيل
$details_field = [
'label' => 'تفاصيل',
'type' => 'text', // Assuming it's a text field
'min_length' => 5,
'max_length' => 255,
'required' => true, // Set the field as required
'_order' => 50, // Display after المجموع
];
// // Merge the fields into the form fields array with proper order
// $form['fields'] = [
'السعر' => $price_field,
'الضريبة' => $vat_field,
'رسوم متر' => $meter_fee_field,
'المجموع' => $total_field,
'تفاصيل' => $details_field,
];
// // Calculate the total based on the entered price
$form['fields']['المجموع']['value'] = isset($_POST['السعر']) ? ($_POST['السعر'] * .15) + 35 + $_POST['السعر'] : '';
return $form;
}
);