Topic: Warning: array_key_exists()
-
Hi
I was told to explain our problem here.
We are getting the following error on a singel product page:
Warning: array_key_exists() expects parameter 2 to be array, bool given in /home/azrtacom/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/functions.php on line 17
please solve this issue as soon as possible.
Attachments:
You must be
logged in to view attached files.
Hi,
Try to add the following PHP code snippet to the child theme functions.php file to fix this
function woodmart_add_brands_to_structured_data( $markup ) {
global $post;
if ( isset( $markup['brand'] ) ) {
return $markup;
}
$brands = get_the_terms( $post->ID, woodmart_get_opt( 'brands_attribute' ) );
if ( ! empty( $brands ) && is_array( $brands ) ) {
// Can only return one brand, so pick the first.
$markup['brand'] = array(
'@type' => 'Brand',
'name' => $brands[0]->name,
);
}
return $markup;
}
add_filter( 'woocommerce_structured_data_product', 'woodmart_add_brands_to_structured_data', 20 );
Kind Regards