我在一个产品类别中使用WPForms,客户在填写表单后会被重定向到购物车。您在其中设置URL的WPForms重定向非常有效,但是,我需要URL是动态的。
我找到了一个带有所需脚本的git,并将其应用于我的函数。php:
function wpf_custom_redirect( $url, $form_id, $fields ) {
// Only consider changing the redirect if its for form #50
$variation_id = 0;
$url = get_site_url();
if ( \'797\' == $form_id ) {
// In the example below, we look at the submitted value for field #5
// If that value is "test", then we change the redirect URL
if ( !empty( $fields[\'4\'][\'value\'] ) && 2 == $fields[\'4\'][\'value\'] ) { //birthdays
$variation_id = 806;
} else if ( !empty( $fields[\'4\'][\'value\'] ) && 1 == $fields[\'4\'][\'value\'] ) { //encouragement
$variation_id = 807;
} else if ( !empty( $fields[\'4\'][\'value\'] ) && 4 == $fields[\'4\'][\'value\'] ) { //spiritual
$variation_id = 809;
} else if ( !empty( $fields[\'4\'][\'value\'] ) && 5 == $fields[\'4\'][\'value\'] ) { //greeting
$variation_id = 810;
} else if ( !empty( $fields[\'4\'][\'value\'] ) && 6 == $fields[\'4\'][\'value\'] ) { //holiday
$variation_id = 808;
}
$url .= \'/cart?add-to-cart=82&variation_id=\'.$variation_id;
}
return $url;
}
add_filter( \'wpforms_process_redirect_url\', \'wpf_custom_redirect\', 10, 3 );
我还确保我的孩子主题有效,我的功能正常。正在使用php。可能是什么问题?非常感谢您的帮助。
谢谢-Eli公司