主题的“ inc”文件夹中的woocommerce.php文件中的覆盖函数
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了主题的“ inc”文件夹中的woocommerce.php文件中的覆盖函数,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2570字,纯文字阅读大概需要4分钟。
内容图文
![主题的“ inc”文件夹中的woocommerce.php文件中的覆盖函数](/upload/InfoBanner/zyjiaocheng/670/508cd147f45a40e9b342de6347cc9acb.jpg)
我一直在寻找答案,但我被困住了.对不起,我一点都不了解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文件中.这应该工作.
内容总结
以上是互联网集市为您收集整理的主题的“ inc”文件夹中的woocommerce.php文件中的覆盖函数全部内容,希望文章能够帮你解决主题的“ inc”文件夹中的woocommerce.php文件中的覆盖函数所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。