• Hi there,

    I found the script for Automatically add a product to cart on visit.
    https://docs.woocommerce.com/document/automatically-add-product-to-cart-on-visit/

    After trying it on my website, it triggers an error to the website. Following is the error message.

    An error of type E_ERROR was caused in line 13 of the file /nas/content/live/acewasteprod/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code. Error message: Uncaught Error: Call to a member function get_cart() on null in /nas/content/live/acewasteprod/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code:13

    Does anyone know how to resolve this issue?

    Thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello there,
    I tested the code on my installation and it works perfectly without triggering any error.

    I suspect that it does not work for you because you are using a plugin (code snippets) to add the code.

    Try adding it using the functions.php file or some other method: https://nicolamustone.blog/2016/03/03/tweak-wp-theme-add-custom-php/

    Thread Starter steve-8bm

    (@steve-8bm)

    Hi Nicola,

    Thank you for your reply.

    I tried putting in the script in both code snippets plugin and in the function.php. Both methods cause the same issue.

    The issue/ error message only happens in the backend of the site when I try to process an ajax function, for example, “Start SEO data optimization” function under Yoast Tools. It causes the issue after I click the button. Following is the screenshot.

    View post on imgur.com

    But after I disable the snippet and runs the function. The function from Yoast can be processed again. Not sure why?

    Thank you in advance,

    Steve

    Thread Starter steve-8bm

    (@steve-8bm)

    Hi Nicola,

    How are you? Hope you had a nice weekend.

    Just want to follow up with my question, wonder if you had any luck with it?

    Thank you,

    Steve

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Automatically add product to cart on visit’ is closed to new replies.