strangerstudios / pmpro-woocommerce

Connect Paid Memberships Pro with WooCommerce and WooCommerce Subscriptions to sell membership products and offer members-only product discounts.
https://www.paidmembershipspro.com/add-ons/pmpro-woocommerce/
46 stars 32 forks source link

Fatal Error Call to a member function get_cart_contents() #91

Closed ogiebobogh closed 6 years ago

ogiebobogh commented 6 years ago

I recently upgraded to v1.5 and now many pages in the site dashboard aren't loading and I'm seeing the following PHP fatal error.

`[26-May-2018 15:02:43 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents() on null in /home/public_html/oslhatestsite/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php:126 Stack trace:

0 /home/public_html/oslhatestsite/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php(83): pmprowoo_cart_has_membership()

1 /home/public_html/oslhatestsite/wp-includes/class-wp-hook.php(286): pmprowoo_is_purchasable(true, Object(WC_Product_Variation))

2 /home/public_html/oslhatestsite/wp-includes/plugin.php(203): WP_Hook->apply_filters(true, Array)

3 /home/public_html/oslhatestsite/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1458): apply_filters('woocommerceis...', true, Object(WC_Product_Variation))

4 /home/public_html/oslhatestsite/wp-content/plugins/woocommerce/includes/class-wc-product-variation.php(477): WC_Product->is_purchasable()

5 /home/public_html/oslhatestsite/wp-content/plugins/woocommerce/inc in /home/public_html/oslhatestsite/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php on line 126`

contemplate commented 6 years ago

I'm seeing many similar errors. @eighty20results can you look into this?

I think this condition may not be working correctly: // only change price if this is on the front end if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {

[Wed May 30 07:08:04.002853 2018] [proxy_fcgi:error] [pid 24596:tid 140672141072128] [client 10.1.1.48:36304] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents() on null in /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php:402\nStack trace:\n#0 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-includes/class-wp-hook.php(286): pmprowoo_get_membership_price('16', Object(WC_Product_Simple))\n#1 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-includes/plugin.php(203): WP_Hook->apply_filters('16', Array)\n#2 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-data.php(703): apply_filters('woocommerce_pro...', '16', Object(WC_Product_Simple))\n#3 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(273): WC_Data->get_prop('price', 'view')\n#4 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/woocommerce/includes/api/class-wc-rest-products-controller.php(588): WC_Product->get_pr...\n'

contemplate commented 6 years ago

Here is another one that show it is firing on the admin. I think that condition needs to be changed to an && as well as maybe ! defined ('DOING_AJAX')

[Wed May 30 08:29:17.807369 2018] [proxy_fcgi:error] [pid 23945:tid 140672861427456] [client 167.142.93.47:50432] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents() on null in /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php:126\nStack trace:\n#0 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php(83): pmprowoo_cart_has_membership()\n#1 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-includes/class-wp-hook.php(286): pmprowoo_is_purchasable(true, Object(WC_Product_Simple))\n#2 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-includes/plugin.php(203): WP_Hook->apply_filters(true, Array)\n#3 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1458): apply_filters('woocommerceis...', true, Object(WC_Product_Simple))\n#4 /home/www/whphx8/room.handsonaswegrow.com/htdocs/wp-content/plugins/woocommerce-product-bundles/includes/class-wc-bundled-item.php(1046): WC_Product->is_purchasable()\n#5 /home/w...\n', referer: https://room.handsonaswegrow.com/wp-admin/post.php?post=4552&action=edit

contemplate commented 6 years ago

OK this Pull request should fix it: https://github.com/strangerstudios/pmpro-woocommerce/pull/92

kumarisavita commented 6 years ago

I have installed PMPRO plugin with woocommerce membership plugin while creating wocommerce product I added the product to the membership plan. After accessing that product i got

Fatal error: Call to undefined method WC_Cart::get_cart_contents() in /home/XXX/public_html/wp-content/plugins/pmpro-woocommerce/pmpro-woocommerce.php on line 251

please help me out in this.

contemplate commented 6 years ago

@kumarisavita you can see the file edits needed here: https://github.com/strangerstudios/pmpro-woocommerce/pull/92/files

ideadude commented 6 years ago

Thanks for the fix. Merged in and ready to go out in the next release (next few days).