I’m trying to add a section in the Settings > Payments dashboard.
Adding the section works, but populating it doesn’t. The filter doesn’t seem to trigger/work.
/classic-commerce/includes/admin/settings/class-wc-settings-payment-gateways:71 is not triggered when my plugin does:
add_filter('woocommerce_get_settings_checkout', 'ajdg_paypal_surcharge_settings', 10, 2);
I’ve been poking around in the code and can’t find a cause. It’s like the filter doesn’t exist in CC.
But it does in the above mentioned file.
For comparison, this works fine:
add_filter('woocommerce_get_sections_checkout', 'ajdg_paypal_surcharge_section');
Both work in WooCommerce 2.2.2 and up. and the code seems the same enough even in WC 3.x-5.6 to imply that it should work on CC too. Seeing that it works half in CC, I imagine it’s a bug in Classic Commerce.
I can’t find any errors in any logs. Nor does ClassicPress/ClassicCommerce seem to acknowledge the filter.
Other than the missing dashboard, the plugin works fine. All other hooks/filters and everything works. Just the settings hook doesn’t work - Further suggesting there is a bug in CC.
Thoughts? Advise?
2 Likes
Is this related?
opened 06:33PM - 13 Sep 15 UTC
closed 09:16AM - 14 Sep 15 UTC
I'm working on a small plugin that needs to add settings to a sub-section under … the 'Checkout' tab.
Creating the sub-section with the `woocommerce_get_sections_checkout` filter works absolutely fine, however when you try to add settings via `woocommerce_get_settings_checkout` it neither works nor makes the `$custom_section` variable available. It generates this error in the admin:
```
Warning: Missing argument 2 for add_plugin_settings() in /srv/www/wordpress-default/wp-content/themes/twentyfifteen/functions.php on line 378
Notice: Undefined variable: current_section in /srv/www/wordpress-default/wp-content/themes/twentyfifteen/functions.php on line 384
```
Quickest way to replicate is to use the Gists found in the official docs below and change the filter names accordingly.
http://docs.woothemes.com/document/adding-a-section-to-a-settings-tab/
There do seem to be a couple of mentions I could find online, but it is way beyond my level of understanding. Pinging @omukiguy to see if he has an idea.
The only other thing I could suggest is to download a copy of WC 3.5.3 and see if it works there. Then we will know for sure that it is something we did.
Also can you post a screenshot of what you are seeing?
james
August 31, 2021, 11:24pm
4
Are you able to share your code - or a minimal example that reproduces the issue you are seeing?
@ozfiddler exactly that yes.
@ozfiddler
This is in Classic Commerce - All works except the dashboard content is missing (due to the filter not working).
https://disk.stor.fit/index.php/s/oZbrMwf8oSWDcQ3
And this one is in WooCommerce 5+ where it works fine. (alo worked in older WC versions)
https://disk.stor.fit/index.php/s/4A98FfiqikLrQRm
Are you saying it works in WC 3.5.3? It looks like it might be a limitation we inherited.
Sorry, missed this. So it does work in WC 3.5.3.
viktor
September 1, 2021, 12:00am
9
That sounds about right. They fixed it in February 2019.
woocommerce:master
← woocommerce:fix/22696
opened 07:45AM - 11 Feb 19 UTC
### All Submissions:
* [x] Have you followed the [WooCommerce Contributing gu… ideline](https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md)?
* [x] Does your code follow the [WordPress' coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/)?
* [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
### Changes proposed in this Pull Request:
This PR fixes a logic error that prevents custom payment section settings to not load and display.
Closes #22696
### How to test the changes in this Pull Request:
1. See sample code in #22696
2. Go to Settings -> Payments -> Custom Page and check that a API field is displayed.
### Other information:
* [x] Have you added an explanation of what your changes do and why you'd like us to include them?
* [ ] Have you written new tests for your changes, as applicable?
* [x] Have you successfully ran tests with your changes locally?
### Changelog entry
> Fix - Custom payment options sections was not loading settings.
Yes, just been testing this using the sample code from the docs. It works on the Products tab but not the Shipping or the Payments. Same result in CC and WC 3.5.3.
Does this look like a fairly straighforward fix we could push in the next release?
viktor
September 1, 2021, 12:13am
11
I don’t know for sure, not my area of exertise, but the changes seem to affect one file:
woocommerce:master
← woocommerce:fix/payment-custom-section-saving
opened 11:33AM - 11 Mar 19 UTC
…o saving the current section.
### All Submissions:
* [x] Have you followe… d the [WooCommerce Contributing guideline](https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md)?
* [x] Does your code follow the [WordPress' coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/)?
* [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
### Changes proposed in this Pull Request:
This PR adds additional fallback to the saving functionality of WC_Settings_Payment_Gateways::save as per #22704 which added functionality to load custom sections on the Payments settings.
### How to test the changes in this Pull Request:
1. Use the custom code as per #22696
2. Go to Settings -> Payments -> Custom Page and check that a API field is displayed.
3. Enter a value in the field and save, it should fall save without having any specific code in place to handle saving.
### Other information:
* [x] Have you added an explanation of what your changes do and why you'd like us to include them?
* [ ] Have you written new tests for your changes, as applicable?
* [x] Have you successfully ran tests with your changes locally?
### Changelog entry
> Add functionality to save custom section in payment gateway settings page using built in WooCommerce option saving functionality.
If you have CC installed already, try testing those changes to that file.
I’m playing with it! I have the new section showing correctly but I have now lost the main payment gateway page
I expect someone who knew what they were doing could probably get it to work fairly easily.
OK - I have it working now. This is the payments section, and a new section added. I will see if I can remember how to do a PR for this.
The documentation of WC says the filters are introduced in 2.2.2.
I’ve created these plugins maybe 2-3 years ago. So whatever version of WC was current then, it works on that for sure.
Hopefully it’s a easy fix and thanks for your efforts!
1 Like
I think it should be fairly easy. I have done a PR…
ClassicPress:master
←
opened 01:39AM - 01 Sep 21 UTC
### All Submissions:
* [x] Have you followed the [Classic Commerce Contributi… ng guideline](https://github.com/ClassicPress-plugins/classic-commerce/blob/master/.github/CONTRIBUTING.md)?
* [x] Does your code follow the [repo standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/)?
* [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
### Changes proposed in this Pull Request:
Change the logic in the class-wc-settings-payment-gateways.php file so that new sections created under the Payments tab will work correctly. This was an existing bug in WC 3.5.3 that was later fixed with this PR: https://github.com/woocommerce/woocommerce/pull/22988
### How to test the changes in this Pull Request:
1. Copy the revised class-wc-settings-payment-gateways.php file to a test installation
2. Create a new section following this tutorial: https://docs.woocommerce.com/document/adding-a-section-to-a-settings-tab/
- make sure you use the woocommerce_get_sections_checkout filter.
3. Visit the Payments tab in the setting and ensure that the new section is showing and the screen displays correctly when clicked.
### Screenshot - before:
![payments0](https://user-images.githubusercontent.com/46998578/131597513-9a1029d2-0157-4124-b964-04973f8d2a21.jpg)
### Screenshot - after:
![payments2](https://user-images.githubusercontent.com/46998578/131597527-767edf17-d3d4-4052-9037-5f298de2d397.jpg)
### Other information:
* [x] Have you added an explanation of what your changes do and why you'd like us to include them?
* [x] Have you written new tests for your changes, as applicable?
* [x] Have you successfully ran tests with your changes locally?
* [x] Have you included screenshots before/after your changes, if applicable?
Discussion on forum is here: https://forums.classicpress.net/t/classiccommerce-not-triggering-filter-for-adding-settings-sections-in-tabs/3508
Thanks to arnandegans for bringing it to our attention.
It needs to be reviewed and we will see when we can get it added.
1 Like
If would be good if you could test it for us. Download the revised file and copy it in to a test site.
yay!
I can confirm this now seems to work on CC1.0.4.
2 Likes
system
Closed
September 3, 2021, 2:01am
18
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.