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”
- This topic has 7 replies, 2 voices, and was last updated 4 weeks, 1 day ago by
Artem Temos.
-
AuthorPosts
-
January 12, 2025 at 1:25 pm #629048
voltraiderParticipantHello,
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.
January 13, 2025 at 10:30 am #629152
Artem TemosKeymasterHello,
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
January 21, 2025 at 6:02 pm #631616
voltraiderParticipantHere’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.January 21, 2025 at 6:36 pm #631628
Artem TemosKeymasterTry 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 );
January 30, 2025 at 11:34 am #634076
voltraiderParticipantThank 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?
January 30, 2025 at 12:21 pm #634084
Artem TemosKeymasterYes, you need to resave products to fix the errors now. It is not related to the plugin.
January 30, 2025 at 12:22 pm #634086
voltraiderParticipantThank’s.
January 30, 2025 at 12:26 pm #634093
Artem TemosKeymasterYou are welcome.
-
AuthorPosts
The topic ‘Error “Warning: in_array() expects parameter 2 to be array”’ is closed to new replies.
- You must be logged in to create new topics. Login / Register