【发布时间】:2019-07-31 09:52:37
【问题描述】:
我一直在寻找答案,但我被困住了。对不起,我根本不懂php。
在我的主题/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() ) 的内容,但我自己无法解决。
你能帮帮我吗?
【问题讨论】:
标签: php wordpress filter woocommerce hook-woocommerce