Home Forums WoodMart support forum Topic: Warning: array_key_exists()

Topic: Warning: array_key_exists()

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #336248

    CHANDAN
    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/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.
    #336250

    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

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