Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How do I add itemprop= WordPress

I run woocommerce and like to add the itemprop condition to my offer (so that google merchant center loves it).

I added this line:
<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" />

So in total my price.php looks now like this:
<?php
/**
* Single Product Price, including microdata for SEO
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/price.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.4.9
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

global $product;

?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">

<p class="price"><?php echo $product->get_price_html(); ?></p>

<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />

</div>


As recommended in the comments of that page I copied it to the templates-folder (template is atelier) here:
wp-content/themes/atelier/woocommerce/single-product

It is not working.
When testing at the google testing tool, the information is missing:
https://search.google.com/structured-data/testing-tool

the file to be tested is e.g. this one:
[[LINK href="http://www.akustikbild-manufaktur.de/produkt/absorber-akustik-bild-online-kaufen-aqua-sq/"]]http://www.akustikbild-manufaktur.de/produkt/absorber-akustik-bild-online-kaufen-aqua-sq/
[[/LINK]]

Answers (2)

2016-05-23

Arnav Joy answers:

please read this

https://www.longren.io/add-schema-org-markup-to-woocommerce-products/

http://wpquestions.com/question/showChrono/id/8482


TanjaB comments:

I read this beforehand.
And I decided that it is not useful for me. Woocommerce has already set the functions and so.
There are already meta-infos in the template.
It is only one specific missing.

Can you help?

2016-05-23

Reigel Gallarde answers:

the problem is that your theme is overriding it using a function found in wp-content\themes\atelier\swift-framework\core\sf-woocommerce.php near or at line 937...

so you have a lot of options... I can list 3.

1. the easiest but I don't recommend is to edit that file...
2. using your functions.php, add a hook to init at priority 4, because that file is being called at priority 5. Then create the same function with your edits.

add_action('init', 'my_wc_sf_edits', 4);
function my_wc_sf_edits() {
if ( ! function_exists( 'sf_product_price_rating' ) ) {
function sf_product_price_rating() {
global $post, $product, $sf_catalog_mode, $wpdb;
?>
<div class="product-price-wrap clearfix">
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">

<h3 class="price"><?php echo $product->get_price_html(); ?></h3>
<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" />
<meta itemprop="price" content="<?php echo $product->get_price(); ?>" />
<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />

<?php if (!$sf_catalog_mode) { ?><link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /><?php } ?>

</div>

<?php
if ( comments_open() ) {

$count = $wpdb->get_var("
SELECT COUNT(meta_value) FROM $wpdb->commentmeta
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
WHERE meta_key = 'rating'
AND comment_post_ID = $post->ID
AND comment_approved = '1'
AND meta_value > 0
");

$rating = $wpdb->get_var("
SELECT SUM(meta_value) FROM $wpdb->commentmeta
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
WHERE meta_key = 'rating'
AND comment_post_ID = $post->ID
AND comment_approved = '1'
");

if ( $count > 0 ) {

$average = number_format($rating / $count, 2);

$reviews_text = sprintf(_n('%d Review', '%d Reviews', $count, 'swiftframework'), $count);

echo '<div class="review-summary"><div class="star-rating" title="'.sprintf(__('Rated %s out of 5', 'swiftframework'), $average).'"><span style="width:'.($average*16).'px"><span class="rating">'.$average.'</span> '.__('out of 5', 'swiftframework').'</span></div><div class="reviews-text">'.$reviews_text.'</div></div>';

}
}
?>

</div>
<?php
}
add_action( 'woocommerce_single_product_summary', 'sf_product_price_rating', 10 );
}
}


3. use child theme and do number 2.


TanjaB comments:

Thanx. This worked!


Reigel Gallarde comments:

Great!

Don't forget to close this question by clicking [[LINK href="http://www.wpquestions.com/question/pickAWinner/id/18391"]]Vote to award prize[[/LINK]].