Site logo

Archived topic

WooCommerce Cart in Menu URL PHP Notice

7 replies · Started by Arthur on October 17, 2017

Viewing posts 1–8 of 8

I'm getting the following error for the href value within the Cart Menu Item generated by GP:

<br />
<b>Notice</b>:  WC_Cart::get_cart_url is <strong>deprecated</strong> since version 2.5! Use wc_get_cart_url instead. in <b>/.../public_html/staging/wp-includes/functions.php</b> on line <b>3831</b><br />
https://www.bigalstoybox.com/staging/cart/

I'm using WooCommerce 3.2.1 and WP 4.8.2.

Should this function be updated in the theme?

Hi there,

GP uses this function: WC()->cart->get_cart_url()

Maybe you have another plugin activated causing it?

Tom, I only have GP Premium and WooCommerce active.

Do you think this is a PHP 7 or 7.1 error? I've tested this on 2 sites, both running on PHP 7.1, and I see the same error.

Tom, I tested the PHP versions and that is NOT the problem. Also, this error is only visible when using define('WP_DEBUG', true).

I noticed the call on line 328 in the functions.php file for the GPP 1.4.3 plugin:

esc_url( WC()->cart->get_cart_url() )

It looks like the error Notice suggests using wc_get_cart_url(). See this: https://docs.woocommerce.com/document/show-cart-contents-total/

Would this be the problem?

Hmm, that's strange. Your error specifically brings up this function: WC_Cart::get_cart_url

That doesn't exist in GP or GPP.

If you look at that example page you linked me to, they use this in their AJAX function (which GP uses):

$woocommerce->cart->get_cart_url();

That is the equivalent to WC()->cart->get_cart_url(), which GPP uses.

I changed WC()->cart->get_cart_url() in the functions.php file to wc_get_cart_url() and the deprecation notice went away. I'm using the default WC AJAX functions (Enable AJAX add to cart buttons on archives) and the Menu Cart value still updates with AJAX using the wc_get_cart_url() function.

I was looking at the code from a standalone WC Cart Menu item plugin (which worked for me), and they used this wc_get_cart_url() with a WC version check.

Is there any reason NOT to use that function?

Not that I can see - I'll look into it some more and will add it to GPP if need be.

Thanks!

Added to the next version of GPP.

Thanks for reporting! :)

This archived topic is closed to new replies.