stream icon indicating copy to clipboard operation
stream copied to clipboard

Plugin conflict with WooCommerce Subscriptions and `woocommerce_available_payment_gateways` filter

Open tyrann0us opened this issue 4 years ago • 4 comments

Bug Report

If the following plugins are active: Stream, WooCommerce and WooCommerce Subscriptions (https://woocommerce.com/products/woocommerce-subscriptions/) and a callback for the woocommerce_available_payment_gateways filter hook uses \WC_Cart->get_cart(), a PHP notice is triggered.

Expected Behavior

No PHP notice(s) should be triggered.

Actual Behavior

A PHP notice is triggered: Notice: Get cart should not be called before the wp_loaded action.

Stack trace (with some comments):

+----------------------------------------------------------------------+-----------------------------------------------------+
|                               Function                               |                      Location                       |
+----------------------------------------------------------------------+-----------------------------------------------------+
| {main}( )                                                            | .../index.php:0                                     |
| require( '/app/public/wp/index.php' )                                | .../index.php:2                                     |
| require( '/app/public/wp/wp-blog-header.php' )                       | .../index.php:17                                    |
| require_once( '/app/public/wp/wp-load.php' )                         | .../wp-blog-header.php:13                           |
| require_once( '/app/public/wp-config.php' )                          | .../wp-load.php:42                                  |
| require_once( '/app/public/wp/wp-settings.php' )                     | .../wp-config.php:213                               |
| do_action( )                                                         | .../wp-settings.php:540                             |
| WP_Hook->do_action( ) // `init`                                      | .../plugin.php:478                                  |
| WP_Hook->apply_filters( )                                            | .../class-wp-hook.php:311                           |
| WP_Stream\Plugin->init( )                                            | .../class-wp-hook.php:287                           |
| WP_Stream\Connectors->__construct( )                                 | .../class-plugin.php:184                            |
| WP_Stream\Connectors->load_connectors( )                             | .../class-connectors.php:52                         |
| WP_Stream\Connector_Woocommerce->register( )                         | .../class-connectors.php:186                        |
| WP_Stream\Connector_Woocommerce->get_woocommerce_settings_fields( )  | .../class-connector-woocommerce.php:67              |
| WC_Settings_Payment_Gateways->get_settings( )                        | .../class-connector-woocommerce.php:735             |
| apply_filters( ) // `woocommerce_payment_gateways_settings`          | .../class-wc-settings-payment-gateways.php:56       |
| WP_Hook->apply_filters( )                                            | .../plugin.php:206                                  |
| WC_Subscriptions_Admin::add_recurring_payment_gateway_information( ) | .../class-wp-hook.php:287                           |
| WC_Subscriptions_Payment_Gateways::one_gateway_supports( )           | .../class-wc-subscriptions-admin.php:1859           |
| WC_Payment_Gateways->get_available_payment_gateways( )               | .../class-wc-subscriptions-payment-gateways.php:115 |
| apply_filters( ) // `woocommerce_available_payment_gateways`         | .../class-wc-payment-gateways.php:160               |
| WP_Hook->apply_filters( )                                            | .../plugin.php:206                                  |
| anyCallbackThatUsesGetCart( ) // <-                                  | .../class-wp-hook.php:287                           |
| WC_Cart->get_cart( )                                                 | .../AnyClass.php:0                           |
| wc_doing_it_wrong( )                                                 | .../class-wc-cart.php:607                           |
| _doing_it_wrong( )                                                   | .../wc-deprecated-functions.php:118                 |
+----------------------------------------------------------------------+-----------------------------------------------------+

Steps to Reproduce the Problem

  1. Install and activate Stream, WooCommerce, WooCommerce Subscriptions
  2. Add a callback for the woocommerce_available_payment_gateways filter hook
  3. Inside the callback, call \WC()->cart->get_cart()

Calling \WC_Cart::get_cart() is a common practice to toggle payment providers based on cart content.

System Information

  • Stream v3.5.0
  • WooCommerce v4.3.1
  • WooCommerce Subscriptions v3.0.4
  • WordPress version: v5.4.2

tyrann0us avatar Jul 23 '20 06:07 tyrann0us

@kasparsd, any change you take a look at this? Thanks!

tyrann0us avatar Jul 25 '20 12:07 tyrann0us

@kopepasah, any chance this issue can be fixed? Thanks!

tyrann0us avatar Nov 22 '21 11:11 tyrann0us

@kasparsd, the bug still occurs with the following system information:

  • Stream v3.8.2
  • WooCommerce v6.2.1
  • WooCommerce Subscriptions v4.0.2
  • WordPress version: v5.9.1

I'd really appreciate it if you could have a look since it's massively spamming our logs. It should be possible to provide you with a copy of "WooCommerce Subscriptions" for testing purposes if need be. Thank you!

tyrann0us avatar Mar 01 '22 19:03 tyrann0us

Hi @kasparsd, this is my semi-annual friendly reminder to ask if you could take a look at this issue. Thanks 🙂

tyrann0us avatar Oct 17 '22 06:10 tyrann0us