• Resolved raha1988ab

    (@raha1988ab)


    Hi

    for optimizing my website , I installed the Query Monitor and it shows me many PHP warning from WooCommerce plugins
    could you please help me what are these and how to fix them?

    WooCommerce/inculudes/admin/class-wc-admin-dashboard.php:543
    WC_Admin_Dashboard->sales_sparkline()
    

    This is the image of those problems
    https://prnt.sc/6EXJohJ-waKw

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Sérgio L. a11n

    (@csnlima)

    Hi @raha1988ab,

    Invalid argument supplied for foreach() error? occurs when PHP’s built-in foreach()tries to iterate over a data structure that is not recognized as an array or object.

    You need to add an additional check before the foreach() function to circumvent the error. There is an example here:

    https://www.educative.io/edpresso/fixing-the-invalid-argument-supplied-for-foreach-php-error

    I hope this information helps.

    Best,

    Thread Starter raha1988ab

    (@raha1988ab)

    So you mean there is not related to my SQL tables ?

    If so , my theme is Woodmart and it is the last update , Now how should I use that code?
    in my function.php file ?
    Please give solution wit more details.
    Thanks

    Hi @raha1988ab

    how should I use that code?

    We recommend using a plugin like Code Snippets to add custom PHP code into your site without directly accessing the functions.php file.

    With the Code Snippets plugin, you just have to activate or deactivate the snippet you add and it will start to execute. To do it, go to Snippets, click the Add new option, paste the code and then click Save Changes and Activate.

    If you have more questions about that plugin, you can create a thread here: https://www.ads-software.com/support/plugin/code-snippets/

    I hope this helps.

    Thread Starter raha1988ab

    (@raha1988ab)

    @margaretwporg
    Hi
    Thanks for information

    I asked 2 question , and you answer the second one.

    I don’t need the code-snippets , thanks

    I just asked that code on that website is true ? and should I put in function.php or not ,

    @csnlima
    Now I add in my function but still get the error

    I don’t know what to do…

    Hello,

    I just asked that code on that website is true ? and should I put in function.php or not

    Yes on the function.php:
    https://woocommerce.com/document/using-theme-functions-php/

    Please note the recommendation for better performance is to do it using a plugin like https://www.ads-software.com/plugins/code-snippets

    I just asked that code on that website is true ? and should I put in function.php or not

    You can refer to the code provided by @csnlima and adjust it to your own needs (Please note using the exact code will not work, it needs to be adjusted). You can make sure your index variable for your foreach cycle is an array (is_array) or an object (is_object) before doing the cycle.

    if (is_array($myList) || is_object($myList))
    {
      // If yes, then foreach() will iterate over it.
      foreach($myList as $arrayItem)
    ...

    May I ask if the site is working wrong? I am asking since the notification received is for a warning.

    If the site is not working as expected you can refer to this documentation to get more information:
    https://woocommerce.com/document/woocommerce-self-service-guide/

    Let us know how it goes.

    Thread Starter raha1988ab

    (@raha1988ab)

    Hi @ihereira

    May I ask if the site is working wrong? I am asking since the notification received is for a warning.

    Site is working , I found the problem but I’m not sure where is come form exactly
    I disabled all plugin except theme and woodmart core plugin , Litespeed cache and query monitor, No there is no error for foreach, It’s related to one or some plugins and I got that error only in backend of WordPress , and it’s showing randomly

    You can refer to the code provided by @csnlima and adjust it to your own needs (Please note using the exact code will not work, it needs to be adjusted).

    How can I adjust the code ? does code snippet do for me the adjust process?

    I need the exact code to solve that issue for ever , and I don’t know where should I found the exact code.

    • This reply was modified 2 years, 9 months ago by raha1988ab.

    Hi @raha1988ab

    If the site is working fine then there isn’t much to worry about right now – It is only a warning and you came to know about it because you installed Query Monitor. If you notice any problem with functioning of the site then that should be a matter of immediate concern.

    I need the exact code to solve that issue for ever , and I don’t know where should I found the exact code

    The code in the second box is complete in itself – you can use it. In case you happen to need any modifications made, then you can seek help at the following places:

    You may also be able to find someone willing to volunteer their time and knowledge in the free PHP support forum at PHP Builder.

    For direct assistance with regards to your site, you may also consider reaching out to someone on our customizations page.

    * Support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.

    Thread Starter raha1988ab

    (@raha1988ab)

    HI @margaretwporg
    Thanks a lot

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WC_Admin_Dashboard->sales_sparkline()’ is closed to new replies.