Home Forums WoodMart support forum PHP warning and error

PHP warning and error

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #634630

    toulip
    Participant

    Hello 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 432

    Can you please assist? It happens really often based on the log but not always.

    Best Regards,

    #634651

    Artem Temos
    Keymaster
    Xtemos team

    Hello,

    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 Builder

    Thank you in advance.

    #634810

    toulip
    Participant

    Hello,

    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?

    #634872

    Artem Temos
    Keymaster
    Xtemos team

    In 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

    #635526

    toulip
    Participant

    Hello 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,

    #635535

    Artem Temos
    Keymaster
    Xtemos team

    Try 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 );
    #635557

    toulip
    Participant

    Ok, 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.

    #635847

    toulip
    Participant

    Hello.

    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?

    #635868

    Artem Temos
    Keymaster
    Xtemos team

    Try 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' );
    });
    #636081

    toulip
    Participant

    Hello,

    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?

    #636184

    Artem Temos
    Keymaster
    Xtemos team

    We have not yet fully investigated this issue, so we cannot confirm whether the code we provided solves the problem or not.

    #636962

    toulip
    Participant

    Hello. 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,

    #637080

    Artem Temos
    Keymaster
    Xtemos team

    We are glad to hear that. You don’t need to do anything else for now.

    Kind Regards

    #637081

    Artem Temos
    Keymaster
    Xtemos team

    We are glad to hear that. You don’t need to do anything else for now.

    Kind Regards

    #637088

    toulip
    Participant

    Great, thanks!

    Have a good day!

    Best Regards,

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘PHP warning and error’ is closed to new replies.