Home Forums WoodMart support forum Warning: array_key_exists()

Warning: array_key_exists()

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #335336

    jensende
    Participant

    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/onsalasol/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/functions.php on line 17

    You can see here: https://onsalasol.se/product/sugar-suede-lush-ultra-nourishing-moisturizer-devoted-creations/

    As I am working for the owner of the website I cant create a login.

    Please check this and get back to med as soon as you ca…Please

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

    Artem Temos
    Keymaster

    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

    #335363

    jensende
    Participant

    Thank you!!

    That worked 🙂

    Great support, do we need to erase this with later updates?

    #335368

    Artem Temos
    Keymaster

    Yes, it will be included in our next theme update so you can erase it then.

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