Home / Forums / WoodMart support forum / PHP warning and error
Home › Forums › WoodMart support forum › PHP warning and error
PHP warning and error
- This topic has 14 replies, 2 voices, and was last updated 1 year, 5 months ago by
toulip.
-
AuthorPosts
-
February 1, 2025 at 1:09 am #634630
toulipParticipantHello guys,
I keep receving messages from my client that often some product pages show a critical error on the frontend. This is not happening all the time. After looking at the server’s php error log, I found the following:
[31-Jan-2025 20:28:00 UTC] PHP Warning: foreach() argument must be of type array|object, string given in /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/modules/parts-css-files/class-parts-css-files.php on line 317
[31-Jan-2025 20:28:00 UTC] PHP Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/modules/parts-css-files/class-parts-css-files.php:432
Stack trace:
#0 /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/modules/parts-css-files/class-parts-css-files.php(432): in_array(‘header-base’, ‘[“helpers-wpb-e…’, true)
#1 /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/enqueue.php(1193): XTS\Modules\Parts_Css_Files->enqueue_inline_style(‘header-base’, false)
#2 /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/modules/header-builder/functions.php(23): woodmart_enqueue_inline_style(‘header-base’)
#3 /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/header.php(26): whb_generate_header()
#4 /home/customer/www/morfes-jewels.gr/public_html/wp-includes/template.php(810): require_once(‘/home/customer/…’)
#5 /home/customer/www/morfes-jewels.gr/public_html/wp-includes/template.php(745): load_template(‘/home/customer/…’, true, Array)
#6 /home/customer/www/morfes-jewels.gr/public_html/wp-includes/general-template.php(48): locate_template(Array, true, true, Array)
#7 /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/woocommerce/single-product.php(16): get_header(‘shop’)
#8 /home/customer/www/morfes-jewels.gr/public_html/wp-includes/template-loader.php(106): include(‘/home/customer/…’)
#9 /home/customer/www/morfes-jewels.gr/public_html/wp-blog-header.php(19): require_once(‘/home/customer/…’)
#10 /home/customer/www/morfes-jewels.gr/public_html/index.php(17): require(‘/home/customer/…’)
#11 {main}
thrown in /home/customer/www/morfes-jewels.gr/public_html/wp-content/themes/woodmart/inc/modules/parts-css-files/class-parts-css-files.php on line 432Can you please assist? It happens really often based on the log but not always.
Best Regards,
February 1, 2025 at 10:53 am #634651Hello,
Please disable any plugins not directly related to our theme and provide us with your admin access details. We will log in to your dashboard and investigate the issue. Please ensure that you only keep the following plugins that are necessary for our theme to work correctly:
– WoodMart core
– WooCommerce
– Elementor/WPBakery Page BuilderThank you in advance.
February 3, 2025 at 12:41 am #634810
toulipParticipantHello,
Thanks for getting back to me.
I am afraid I cannot do that since this is an active website with a lot of traffic. Please allow me some time to create a staging version for you and send over the login details.
In the meantime, is there anything else we could check?
February 3, 2025 at 11:07 am #634872In this case, you need to create a staging development copy of your website. There, you will be able to do such kind of experiments without any harm to your production website.
Kind Regards
February 5, 2025 at 11:05 am #635526
toulipParticipantHello please look at the login details in the Private content area.
Again, the error does not show all the time. It is at random times in the day. And it is only related to product single pages, not any other pages or archives on the website.
I hope this helps.
Please advise.
Best Regards,
February 5, 2025 at 11:20 am #635535Try to add the following PHP code snippet to the child theme functions.php file to fix this
function wd_exclude_post_meta_from_woocommerce_app( $response, $product, $request ) { $excluded_meta_keys = [ 'wd_page_css_files', 'wd_page_css_files_mobile', ]; if ( isset( $response->data['meta_data'] ) && is_array( $response->data['meta_data'] ) ) { foreach ( $response->data['meta_data'] as $index => $meta ) { if ( is_object( $meta ) && isset( $meta->key ) && in_array( $meta->key, $excluded_meta_keys, true ) ) { unset( $response->data['meta_data'][ $index ] ); } elseif ( is_array( $meta ) && isset( $meta['key'] ) && in_array( $meta['key'], $excluded_meta_keys, true ) ) { unset( $response->data['meta_data'][ $index ] ); } } $response->data['meta_data'] = array_values( $response->data['meta_data'] ); } return $response; } add_filter( 'woocommerce_rest_prepare_product_object', 'wd_exclude_post_meta_from_woocommerce_app', 10, 3 );February 5, 2025 at 11:53 am #635557
toulipParticipantOk, thanks. I will paste it right away and continue to keep track of the log. Please allow me 2 days to see if this is going to appear again.
I will come back soon enough!
Thanks for your quick response.
February 6, 2025 at 11:05 am #635847
toulipParticipantHello.
Unfortunately, the error still shows on the php_errorlog file on the server. The provided code does not seem to have fixed the issue.
Any other ideas?
February 6, 2025 at 12:33 pm #635868Try to add the following code snippet as well. Add it and reload your website once. Then remove the code but keep the part provided in the previous reply. Let us know if it helps
add_action( 'init', function () { delete_post_meta_by_key( 'wd_page_css_files' ); delete_post_meta_by_key( 'wd_page_css_files_mobile' ); });February 6, 2025 at 9:56 pm #636081
toulipParticipantHello,
Thanks for your reply.
I did so, and as I mentioned before I will now continue to keep track of the php_errorlog file for the next couple of days.
I will let you know if the error appears again or not.
Thanks again.
Btw, is this fix going to be part of the next theme’s version or is it just a bug that happened to my website for some reason?
February 7, 2025 at 10:36 am #636184We have not yet fully investigated this issue, so we cannot confirm whether the code we provided solves the problem or not.
February 10, 2025 at 6:24 pm #636962
toulipParticipantHello. Thanks for your reply.
Fortunately, the error has not showed up again in the php_error log file which is good. I believe that the issue has been fixed. What do you think? Do I need to check anything else? Neither has the client mentioned to me any php errors while visiting the front end.
Best Regards,
February 11, 2025 at 10:20 am #637080We are glad to hear that. You don’t need to do anything else for now.
Kind Regards
February 11, 2025 at 10:20 am #637081We are glad to hear that. You don’t need to do anything else for now.
Kind Regards
February 11, 2025 at 10:37 am #637088
toulipParticipantGreat, thanks!
Have a good day!
Best Regards,
-
AuthorPosts
The topic ‘PHP warning and error’ is closed to new replies.
- You must be logged in to create new topics. Login / Register