我不知道为什么wpforms_process_redirect_url
不起作用。我用过this 相反
以下是我的完整代码:
//Capture the wpform submit, and call the "processForm" function
add_action( \'wpforms_process_complete\', \'processForm\', 5, 4 );
function processForm( $form_fields, $entry, $form_data, $entry_id ) {
$card_arr = array(797, 1104, 1103, 1102, 1101, 1038, 997, 996, 973, 812);
$form_id = $form_data[\'id\'];
$variation_id = 0;
$url = get_site_url();
// Get the full entry object
$entry = wpforms()->entry->get( $entry_id );
// Fields are in JSON, so we decode to an array
$entry_fields = json_decode( $entry->fields, true );
//$form_data contains the user inputs
//here you could validate your form
if(!in_array($form_id, $card_arr)) {
exit();
} else if ( in_array($form_id, $card_arr)) {
if($form_id == 797){
if ( $entry_fields[4][\'value_raw\'] == 2 ) { //birthdays
$variation_id = 806;
}
if ( $entry_fields[4][\'value_raw\'] == 1 ) { //encouragement
$variation_id = 807;
}
if ( $entry_fields[4][\'value_raw\'] == 4 ) { //spiritual
$variation_id = 809;
}
if ( $entry_fields[4][\'value_raw\'] == 5 ) { //greeting
$variation_id = 810;
}
if ( $entry_fields[4][\'value_raw\'] == 6 ) { //holiday
$variation_id = 808;
}
}
$url .= \'/cart/?add-to-cart=82&variation_id=\'.$variation_id;
wp_redirect($url);
exit();
}
}