admin管理员组文章数量:1414621
Working on a woocommerce gateway and i am trying to make it in such a way that when users saved changes on the woocommerce payment gateway settings page, some values are updated in the admin setting page and if User saves the Admin settings page, it should update the woocommerce payment gateways settings.
I have been able to do it one-way but its not working the other way round, if i save the changes from woocommerce settings API page for the gateways, it updates on the Admin Settings API page. But if i try to save setting from the Admin Settings API page, it doesn't save as the options from the woocommerce setting page will always override the new settings.
INSTANCE:
I saved the following options on WooCommerce Payment settings page;
'Test Mode' = 'Yes';
'secret Key' = 'theSecretKey';
'public Key' = 'thePublicKey';
When i check the Admin Settings page, the necessary fields are auto-populated with the options;
'Test Mode' = 'Yes';
'secret Key' = 'theSecretKey';
'public Key' = 'thePublicKey';
Now when i try to save a new values which from the Admin settings Page (which is to reflect on the woocommerce gateway page) with the following options;
'Test Mode' = 'No';
'secret Key' = 'theSecretKeyNEW';
'public Key' = 'thePublicKeyNEW';
And i hit save changes, it doesn't save or update the woocommerce options; Instead it will reset to what we set from the woocommerce payment settings page;
'Test Mode' = 'Yes';
'secret Key' = 'theSecretKey';
'public Key' = 'thePublicKey';
MY CODE
if ( get_option('woocommerce_gateway_options')['test_mode'] == 'yes' && get_option('admin_setting_options')['test_mode'] == 'no' ) {
$update_admin_options = get_option('admin_setting_options');
$update_admin_options['test_mode'] = 'yes';
update_option( 'admin_setting_options', $update_admin_options );
}elseif(get_option('woocommerce_gateway_options')['test_mode'] == 'no' && get_option('admin_setting_options')['test_mode'] == 'yes') {
$update_admin_options = get_option('aiops_settings_options');
$update_admin_options['test_mode'] = 'active';
update_option( 'admin_setting_options', $update_admin_options );
}
if ( isset(get_option('woocommerce_gateway_options')['secret_key']) || isset(get_option('woocommerce_gateway_options')['public_test']) ) {
$update_admin_options = get_option('admin_setting_options');
$update_admin_options['secret_key'] = get_option('woocommerce_gateway_options')['secret_key'];
$update_admin_options['public_test'] = get_option('woocommerce_gateway_options')['public_test'];
update_option( 'admin_setting_options', $update_admin_options );
}
/* The Above Code works and updates the Admin settings
* when the payment option page is updated.
* NOW, when i add the below code to vise versa the saving, it doesn't work
*/
if ( isset(get_option('admin_setting_options')['secret_key']) || isset(get_option('admin_setting_options')['public_test']) ) {
$update_woocommerce_payment_options = get_option('woocommerce_gateway_options');
$update_woocommerce_payment_options['secret_key'] = get_option('admin_setting_options')['secret_key'];
$update_woocommerce_payment_options['public_test'] = get_option('admin_setting_options')['public_test'];
update_option( 'woocommerce_gateway_options', $update_woocommerce_payment_options );
}
Not sure exactly what i'm doing wrong, as i'm not sure why it isn't working. Thanks in advance for your help.
本文标签: plugin developmentUpdating Woocommerce Settings API when Wordpress Settings API saved and vise versa
版权声明:本文标题:plugin development - Updating Woocommerce Settings API when Wordpress Settings API saved and vise versa 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745176536a2646265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论