I need to capture the value of the option deadlinemaxsale that the user selects in the select charge_field and use it in the sql query resultsplpag. This way display the related results in select plpag_field. However, when the user is changing the option, the $prazomaxvenda variable is not being updated. Here's the code for the function I'm creating.
function custom_checkout_field( $checkout ) {
$current_user = wp_get_current_user();
global $wpdb;
$results = $wpdb->get_results("SELECT codcob, cobranca, prazomaxvenda FROM wptkyb_cobranca WHERE nivelvenda >= (SELECT nivelcli FROM wptkyb_nivelclientes WHERE cgcent = $current_user->user_login)");
echo '<div id="custom_checkout_field" how="formas-pagamento"><h3>'.__('Formas de pagamento:').'</h3>';
echo '<select name="cobranca_field" id="cobranca_field>';
foreach ($results as $result) {
echo '<option value="' . $result->codcob . '">' . $result->cobranca . '</option>';
}
$prazomaxvenda = $results[0]->prazomaxvenda; // armazena o valor de prazomaxvenda
echo '</select></div>';//Fim da div de cobranca_field
echo "Valor de prazomaxvenda: $prazomaxvenda";
echo '<div id="custom_checkout_field2" how="prazo-pagamento"><h3>'.__('Prazo de pagamento:').'</h3>';
echo '<select name="plpag_field" id="plpag_field">';
$resultsplpag = $wpdb->get_results("SELECT codplpag, descricao FROM wptkyb_plpag WHERE prazomedio <= $prazomaxvenda");
foreach ($resultsplpag as $result) {
echo '<option value="' . $result->codplpag . '">' . $result->descricao . '</option>';
}
echo '</select></div><br>';
}// End function
I tried to change the position of the variable but it didn't work, I think I have to capture the change event in the select but I couldn't do it. If the variable changes according to the user's selection, I think it will work fine