Support » Plugin: Yoast SEO » Schema for product : Google Analytics Error – either “offers” …

  • Resolved nir0ma

    (@nir0ma)


    Hi,

    I have a custom post type product and I can’t figure how to alter schema markup to specify “offers” as asked by the search console …

    So i got the followig error message “either “offers”, “review”, or aggregaterating should be specified”

    Th following function is partially working, now products are seen as products and name, description, color … are working except for the “offers” part.

    I thought that creating an array for offers would work, but obvisouly that’s not the way to achieve that … Could you suggest me some hints ?

    function wpseo_schema_for_product( $data ) { 
        if ( isProduct(get_post_type()) ) {
    	$id  = get_the_ID();
            $data['@type'] = 'Product'; 
            $data['author'] = '';
            $data['publisher'] = '';
            $data['headline'] = '';
            $data['datePublished'] = '';
            $data['dateModified'] = '';
            $data['commentCount'] = '';
            $data['articleSection'] = '';
            $data['isPartOf'] = '';
            $data = array_filter($data); 
            $data['name'] = get_the_title($id);
            $data['description'] = get_post_field('post_content', $id) ? get_post_meta( $id, 'product_model', true ) : __('N/S', 'txtdom');
            $data['color'] = get_post_meta( $id, 'product_color', true ) ? get_post_meta( $id, 'product_color', true ) : __('N/S', 'txtdom');
            $data['offers'] = array(
                '@type' => 'Offer',
                'price' => get_post_meta( $id, 'product_price', true ) ? get_post_meta( $id, 'product_price', true ) : "0.00",
                'priceCurrency' => get_post_meta( $id, 'product_currency', true ) ? get_post_meta( $id, 'product_currency', true ) : 'USD',
            );
        }
        return $data; 
    }

    Thank you

    • This topic was modified 5 months, 4 weeks ago by nir0ma.
    • This topic was modified 5 months, 4 weeks ago by nir0ma.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.