我一直在寻找答案,但我被困住了.对不起,我一点都不了解php.
我的theme / inc / functions /文件夹中有一个名为woocommerce.php的文件
Here is a link to the complete code
我要替换这部分代码(从1067行到1080行)
add_filter( 'woocommerce_registration_errors', 'registration_errors_validation', 10, 3 );
function registration_errors_validation( $reg_errors, $sanitized_user_login, $user_email ) {
global $porto_settings, $woocommerce;
if ( isset( $porto_settings['reg-form-info'] ) && 'full' == $porto_settings['reg-form-info'] && 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
extract( $_POST );
if ( strcmp( $password, $confirm_password ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'porto' ) );
}
return $reg_errors;
}
return $reg_errors;
}
有了这个:
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $porto_settings, $woocommerce;
if( isset( $porto_settings['reg-form-info'] ) && $porto_settings['reg-form-info'] == 'full' && 'no' === get_option( 'woocommerce_registration_generate_password' ) ){
extract( $_POST );
if ( strcmp( $posted['account_password'], $posted['account_confirm_password'] ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'porto' ) );
}
return $reg_errors;
}
return $reg_errors;
}
我尝试将修改后的代码粘贴到主题的functions.php中,但是收到一个致命的错误选项,提示无法重新声明函数registration_errors_validation.我还使用inc / functions /子文件夹创建了一个子主题,并将修改后的woocommerce.php文件复制到了那里.最后,我还将woocommerce.php文件复制到了子根文件夹中.
没事.
我已经读过一些在开始时添加if(!function_exists())的内容,但我自己无法解决.
你能帮助我吗?
解决方法:
由于这是一个筛选器挂钩,因此在具有更高优先级的挂钩的重命名函数中使用代码应替换Porto主题的筛选数据……请尝试以下操作:
add_filter( 'woocommerce_registration_errors', 'custom_registration_errors_validation', 20, 3 );
function custom_registration_errors_validation( $reg_errors, $sanitized_user_login, $user_email ) {
global $porto_settings;
if ( isset( $porto_settings['reg-form-info'] ) && 'full' == $porto_settings['reg-form-info'] && 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
extract( $_POST );
if ( strcmp( $posted['account_password'], $posted['account_confirm_password'] ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'porto' ) );
}
}
return $reg_errors;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.这应该工作.