Home Forums WoodMart support forum Error “Warning: in_array() expects parameter 2 to be array”

Error “Warning: in_array() expects parameter 2 to be array”

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #629048

    voltraider
    Participant

    Hello,

    I’ve encountered an issue with the Woodmart theme. When uploading product images via the official WooCommerce mobile app, I’m getting the following error on the product page:

    Warning: in_array() expects parameter 2 to be array, string given in /home/miashoes/mia-shoes.com/www/wp-content/themes/woodmart/inc/modules/parts-css-files/class-parts-css-files.php on line 432
    The error seems to originate in the enqueue_inline_style() function. The problematic part of the code is:

    Ploblem Line – if ( ! isset( $config[ $key ] ) || in_array( $key, $page_files, true ) || ( woodmart_is_combined_needed( ‘combined_css’ ) && ! $ignore_combined ) || isset( $GLOBALS[‘wd_page_css_ignore’] ) ) {
    return;
    }

    It seems that the variable $page_files is not always an array, which causes in_array() to throw this error.

    When I save the product via the standard WordPress editor (not the WooCommerce app), the error disappears. This makes me think it might be related to how the WooCommerce app saves product data.

    #629152

    Artem Temos
    Keymaster

    Hello,

    Could you please record a short video and describe how can we reproduce the issue on your website so we can check this for you?

    Kind Regards

    #631616

    voltraider
    Participant

    Here’s a product photo added via the Woocommerce iPhone app. After that, there is such an error on the product.
    If you go to edit the product through the browser and save, the error disappears.

    Attachments:
    You must be logged in to view attached files.
    #631628

    Artem Temos
    Keymaster

    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 );
    #634076

    voltraider
    Participant

    Thank you. Inserted the code. The old products that were added in this way remained unchanged and the error is visible on them. After re-saving, everything is ok.

    I am trying to add new ones – there is no error yet.

    Also, I still think that the problem could be due to the fact that I had XML-RPC disabled through the ASE plugin (improvement). Do you think it could be related to that?

    #634084

    Artem Temos
    Keymaster

    Yes, you need to resave products to fix the errors now. It is not related to the plugin.

    #634086

    voltraider
    Participant

    Thank’s.

    #634093

    Artem Temos
    Keymaster

    You are welcome.

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

The topic ‘Error “Warning: in_array() expects parameter 2 to be array”’ is closed to new replies.